in reply to Reading files in scalar context with <> operator
That also tends to allow others reading your code to understand your code, especially if they still do not know the ins and outs of contextual returns..... my @lines = <$fh>; my $count = scalar @lines; ....
Here we localize the input record seperator, or enable 'slurp' mode, and the call using <> will pull in the whole file.# Unstested my strict; my warnings; my $content = ''; my $filename = 'myfile.txt'; { local $\; open $fh, '<', $filename or die "Cannot open $filename: $!\n"; $content = <$fh>; close $fh; } print $content;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reading files in scalar context with <> operator
by senőr_biggles (Novice) on Aug 06, 2005 at 19:19 UTC |