I might be misunderstanding your question - do you want to build a new array of records which match in the nth column?
I would probably do this instead (and being explicit about where the variables come from always helps me later when I'm banging my head against the wall).
for my $rec ( @recs ) {
my @rec = split(/:/,$rec);
next unless @rec;
push (@goodrecs,$rec) if( $rec[$n] =~ /$pattern/ );
}
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).
my @goodrecs = grep { my @rec = split(/:/,$_);
$rec[$n] =~ /$pattern/; } @recs;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.