in reply to Example for EOF

Hi guys,

Thank you those who have responded for my question..

i am sorry to say that, i didnt get what i expected..

my aim is: when i reach the last line of the file.. i will add some text to that line and finish the program.

pls help me..

Thanks

Franklin

Don't put off till tomorrow, what you can do today.

Replies are listed 'Best First'.
Re^2: Example for EOF
by neosamuri (Friar) on Nov 15, 2005 at 06:35 UTC
    I beleive then what you want to do is to open in "+>" mode for read write. Then read the file then start writing.
Re^2: Example for EOF
by spiritway (Vicar) on Nov 15, 2005 at 06:55 UTC

    If all you're doing is writing to the end of the file, it's easy. When you open it, open it to "append" - meaning, what you write is added to the end of the file.

    open FH, ">>", $file or die "Can't open $file: $!";

    It's always a good idea to test when you open, in case something happened. If you don't, you may have a very hard time figuring out what went wrong, later on.

Re^2: Example for EOF
by nysus (Parson) on Nov 15, 2005 at 06:54 UTC
    So, it sounds like you are saying "I want to append data to the end of my file." If that's true, follow the advice of the comment below and read up on the open() function. It tells you how to open a file to append it.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
    $nysus = $PM . $MCF;
    Click here if you love Perl Monks

Re^2: Example for EOF
by blazar (Canon) on Nov 15, 2005 at 11:19 UTC
    my aim is: when i reach the last line of the file.. i will add some text to that line and finish the program.

    Oh "XY", then: you really want to ask X, but you think you need Y to do that, and ask about Y.

    This sounds like: "I want to append to the end of file". If so, then just either open in >> mode if you only want to append, or +> if you also want to read it before writing something in it.