grep is normally used to return a list, like this:
my @new_list = grep { /regular expression/ } @list;
now, @new_list contains every value in @list that matches /regular expression/.
Your code:
($i)= grep { m/^#/ } $_;
push @new, $i;
Will set $i to undefined if $_ doesn't start with a # character, and then push it onto @new.
In other words you'll have undefined entries in @new where you probably wanted to skip those lines.
You might want to do some reading in the excellent perl documentation
updated: fixed link
|