Beefy Boxes and Bandwidth Generously Provided by pair Networks
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??


in reply to golf anyone? (taking first field)


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;

--
John.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://224918]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found