in reply to Re: grep fields
in thread grep fields

If there are 21 fields in each record, and the 4th field is an email address, and you want @goodrecs to hold just those records having a specific email address in that field, then consider this question:

Is it ever possible that the email address you're searching for could occur in some other field but not in the 4th field? (I would assume that if "target@email.address" is in field 6 and not in field 4, then it's not a "goodrec".)

If the records containing the target string always have that string in field 4, then you don't have to split:

@goodrecs = grep /:target\@email\.address:/, @recs; # (note the delimiters are part of the match)
But if that condition does not hold for your data, then split is the best approach, as others have suggested. And in that regard, if you're actually looking for one specific string at a time (as opposed to, say, all email strings that have digits before the "@"), then it may be better not to use a regex:
@goodrecs = grep { @f=split/:/; $f[4] eq $target } @recs;
This avoids getting "bigjoe@hotmail.com" and "dumbjoe@hotmail.com" when you were looking for just "joe@hotmail.com", in case that matters to you.

(update: Maybe the latter snippet should say $f[3], if "field 4" is based on the first field being "field 1".)