Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: How to handle a variable number of results from split()?

by Transient (Hermit)
on Jul 20, 2005 at 17:17 UTC ( [id://476569]=note: print w/replies, xml ) Need Help??


in reply to Re: How to handle a variable number of results from split()?
in thread How to handle a variable number of results from split()?

Aye, there is.. and I'm sure there's a more compact way than this one as well :)
#!/usr/bin/perl use strict; use warnings; { local ($,,$\) = (" - ","\n"); while (<DATA>) { chomp; print split(/-/) for split(/,/) } } __DATA__ 1-2,3-4,2-5 2-1,2-5 3-5,1-9,2-2,4-8

Replies are listed 'Best First'.
Re^3: How to handle a variable number of results from split()?
by jdporter (Paladin) on Jul 20, 2005 at 18:43 UTC
    Well, if that's exactly how you want the output:
    { local $/; local $_ = <DATA>; s/,/\n/g; s/-/ - /g; print }
    Or
    open P, ' | perl -laF, -ne "s/-/ - /, print for @F" '; print P <DATA>; close P;
    (Some things are done more succinctly on the command line.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-03-28 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found