Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: regex to an array , is there a better way to do this

by ikegami (Patriarch)
on Jul 08, 2009 at 17:11 UTC ( #778350=note: print w/replies, xml ) Need Help??


in reply to regex to an array , is there a better way to do this

my @array = map { /^(\d+)\.\.(\d+)$/ ? $1..$2 : $_ } split /,/, $seq;

If you're worried about overlaps and/or duplicates,

my %seen; my @array = grep !$seen{$_}++, sort { $a <=> $b } map { /^(\d+)\.\.(\d+)$/ ? $1..$2 : $_ } split /,/, $seq;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2023-01-29 22:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?