Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How can I make it to a one liner

by ikegami (Patriarch)
on Oct 08, 2007 at 07:19 UTC ( [id://643408]=note: print w/replies, xml ) Need Help??


in reply to How can I make it to a one liner

Treat "," as the end of line marker (-054).
Every third line ($. % 3 == 0),
change the trailing comma to a newline (s/,/\n/).
Print the result (-p).

perl -054pe"$.%3||s/,/\n/"

In action:

>echo a,b,c,d,e,f,g,h,i | perl -054pe"$.%3||s/,/\n/" a,b,c d,e,f g,h,i

Update: As moritz points out, I assumed all the input is on one line.

Log In?
Username:
Password:

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

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

    No recent polls found