in reply to Openind file for read+append

jaldama:

You're reading from the end of the file, so you won't find anything. Example:

$ cat t.pl #!/usr/bin/perl use strict; use warnings; use autodie; open my $FH, '>', 'TEST.x'; print $FH <<EOTXT; now is the time for all good men to come to the aid of their party. EOTXT close $FH; open $FH, '+>>', 'TEST.x'; while (<$FH>) { chomp; print "$.: $_\n"; } print $FH "foobar\n"; close $FH; $ perl t.pl $ cat TEST.x now is the time for all good men to come to the aid of their party. foobar

As you can see, it didn't find *anything* to print, but added 'foobar' to the end of the file. You can either use '+>' to put the file in I/O mode or use seek to position the file handle to the beginning of the file before reading.

...roboticus

When your only tool is a hammer, all problems look like your thumb.