Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^6: Convert an array of numbers into a range

by rmocster (Novice)
on Jul 22, 2016 at 01:18 UTC ( [id://1168303]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Convert an array of numbers into a range
in thread Convert an array of numbers into a range

WOW, that is perfect. Big Thanks. Can you give a brief explanation of the syntax if you don't mind? Again thanks.
  • Comment on Re^6: Convert an array of numbers into a range

Replies are listed 'Best First'.
Re^7: Convert an array of numbers into a range
by Anonymous Monk on Jul 22, 2016 at 01:43 UTC
    #!/usr/bin/perl -l # http://perlmonks.org/?node_id=1168288 use strict; use warnings; my @ra = qw(0001 0002 0003 011 012 013 015 16 17 18 20); $_ = join ',', @ra; s/\b # find a number boundary (\d+) # and a number $1 (?{$1}) # save the number in $^R \K # then leave the above in the string (?: # non-capture grouping , # comma - also forces $1 to be a complete number (\d+) # a complete number (because of , and \b) \b # forces comlete number (??{ # extended pattern ++$^R != $2 # false if correct number || length$1 != length$2 # false if same length }) # false (and therefor matches) if both false, other +wise fails # if true returns 1 which can't match because of th +e \b )+ # repeat at least once /-$2/gx; # replace second or more with last matching number print;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2026-04-13 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.