I am currently reading a file and storing the data in an array named @lines
. Then, I loop through this array using a for
loop and inside the loop I
You could also use the File::Slurp module, which is convenient.
use strict;
use warnings;
use File::Slurp 'read_file';
my $fname = shift or die 'filename!';
my @lines = grep /fever/, read_file $fname; # grep with regular expression
print @lines;
If you're new to Perl, take a look at the map
and grep
operators, which are handy for processing lists.
Also, take a look at the ack utility, which is a great replacement for find
/grep
. (Actually, it's a superior alternative.)