Don't ask to ask, just ask | |
PerlMonks |
Re: golf anyone? (taking first field)by jmcnamara (Monsignor) |
on Jan 07, 2003 at 09:16 UTC ( [id://224918]=note: print w/replies, xml ) | Need Help?? |
The following should do what you require: @a = map{(split)[0]}@a; As an un-golfed one-liner I would write it like this: perl -lane 'print $F[0] if @F' file Update: I see that you added a specific requirement for lines that begin with ":" in one of your follow ups. In Golf that's not fair since it means that we would have to have read all of the other posts before posting a reply. Anyone interested in posting a Golf challenge should read Tips on Writing a Golf Challenge. The following handles the special case (the ^ is probably optional): @a = grep!/^:/,map+(split)[0],@a;
--
In Section
Seekers of Perl Wisdom
|
|