{ local $/; # slurp in a file my $contents = <$fh> ... } # now we go back to reading a file line-by-line again while (<$fh>){ ... }
Parenthetic note: in the quoted example code, the $fh file handle would become "exhausted" after the "slurp" read to $contents and the subsequent while-loop read of the handle would produce nothing. A seek operation is needed to reset the logical file position back to the beginning of the file (update: or at least to somewhere other than the end) so that subsequent reads may be successful. Try the following code without the seek statement:
c:\@Work\Perl\monks\pmpmmpmp>perl -wMstrict -le "open my $fh, '<', 'junk.txt' or die $!; ;; my $contents = do { local $/; <$fh>; }; print qq{[[$contents]]}; ;; seek $fh, 0, 0; print 'now we go back to reading a file line-by-line again'; while (<$fh>){ print qq{<<$_>>}; } " [[line 1 fee fie foe line 2 wibble wobble line 3 blah yada ]] now we go back to reading a file line-by-line again <<line 1 fee fie foe >> <<line 2 wibble wobble >> <<line 3 blah yada >>
Give a man a fish: <%-{-{-{-<
In reply to Re^4: restrict use of regex module in script
by AnomalousMonk
in thread restrict use of regex module in script
by pmpmmpmp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |