Hi
My program takes is supposed to take regular expression and a file
containing a list of words/lines as input and print all those lines
that match the regular expression. Below is the program
#!/usr/bin/perl
use strict;
use warnings;
sub grep_file {
my $pattern = shift;
my @file_names = @_;
for my $file_name (@file_names) {
open my ($file_handle), $file_name;
while(my $line = <$file_handle>) {
if ($line =~ m/$pattern/) {
print $line;
}
}
close $file_handle;
}
}
grep_file @ARGV;
When I execute this program from the command line by running "./
grep.pl (.es.){3} /usr/share/dict/words" , I get the error
bash: syntax error near unexpected token `.es.'
But, if execute it as "./grep.pl \(.es.\){3} /usr/share/dict/
words" , I get the expected result.
Please help me understand this.
Thread Next