Reading and writing to a file

Discussion in 'Perl Misc' started by MJS, Aug 3, 2003.

  1. MJS

    MJS Guest

    Hello All,

    I am new to perl and I need some help with the following problem.

    I have two files viz. file1 and file2. I have to determine if a scalar
    variable in file1 (without knowing its location) has a certain value
    (say 10). If its true, then I have to add file2 to file1 at a certain
    location.

    So my question is how to do this and how to write at a certain
    location in file1.

    I would highly appreciate your help.

    Thanks in anticipation.
    MJS, Aug 3, 2003
    #1
    1. Advertising

  2. Gunnar Hjalmarsson, Aug 3, 2003
    #2
    1. Advertising

  3. MJS <> wrote:

    > I have to determine if a scalar
    > variable in file1



    Huh? Files are "data", not "code".

    Only "code" has variables in it.

    Whatever you were trying to say there, you didn't say it correctly...


    > (without knowing its location)



    If it is impossible to find it, then it is impossible to operate on it.

    There must be _some_ way to determine where it is.

    What way is that?

    Is there some text that always comes before/after it?

    Is it always on line N ?

    At the end of a line?

    If you show us an example of your data, and what part you want
    to extract, then we can probably help you with that part.

    If you don't, then we can't.


    > has a certain value
    > (say 10).



    ==


    > So my question is how to do this



    I dunno. Your "this" is known only to you at this point...


    > and how to write at a certain
    > location in file1.



    perldoc -q file

    How do I change one line in a file/delete a line in a
    file/insert a line in the middle of a file/append to the
    beginning of a file?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Aug 3, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Hearn
    Replies:
    1
    Views:
    318
    avnrao
    Jun 30, 2004
  2. HNguyen
    Replies:
    4
    Views:
    2,399
    HNguyen
    Dec 21, 2004
  3. Giulio
    Replies:
    0
    Views:
    377
    Giulio
    Sep 22, 2003
  4. Keith Dewell
    Replies:
    7
    Views:
    488
    Keith Dewell
    Oct 1, 2003
  5. Replies:
    7
    Views:
    521
Loading...

Share This Page