in reply to Reading from a file
Or you could always use the Fatal module to do that for you.open(file1, "sample.txt") or die("ack - $!");
Now on the second line you are reading the entire file into memory.
This is because you are evaluating the filehandle readline operator in a list context, which (prototypes forbidding) is how all function arguments are evaluated, and in list context the filehandle readline operator will read until an eof has been reached. Now when you go to assign $line1 the filehandle file1 has read to the end of the file so returns nothing. Now if you want to get back to the beginning of the file then you'll need to use seek which sets the filehandle's pointer e.gprint(<file1>);
However if you simply want to print a single line from file1 then you'll need to force scalar context which can be done using the scalar function e.gseek(file1, 0, 0);
See. open, readline, eof, seek, scalar and the Input and output functions section of perlfunc for more info.print scalar(<file1>);
_________
broquaint
|
|---|