in reply to grep fields
However, if you wanted to write grep statement to achieve your wish of matching the nth field (which I assume is delimited by ':' this should work (of course where $n and @recs are defined ahead of time).for my $rec ( @recs ) { my @rec = split(/:/,$rec); next unless @rec; push (@goodrecs,$rec) if( $rec[$n] =~ /$pattern/ ); }
my @goodrecs = grep { my @rec = split(/:/,$_); $rec[$n] =~ /$pattern/; } @recs;
|
|---|