Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Parsing a string for sorting

by eak (Monk)
on Aug 08, 2000 at 04:12 UTC ( #26704=note: print w/replies, xml ) Need Help??


in reply to Parsing a string for sorting

How about this one liner.
my $string="001003051"; &verify($_) for(split /(\d{3})/, $string);
If you are worried about non-numbers creeping into your string, you would have to add a 'tr'. --eric

Replies are listed 'Best First'.
RE: Re: Parsing a string for sorting
by merlyn (Sage) on Aug 08, 2000 at 04:19 UTC
    I've really fallen in disfavor with using the "delimiter capturing" mechanism of split, when the list-context m//g is so much more direct and controllable:
    verify($_) for $string =~ /\G(\d{3})/g;
    There. Now there's no chance that "012xxx345xxx678" will try to verify the 345 and 678, as it would for the split example (not to mention passing the xxx parts to verify.

    -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2022-01-24 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (65 votes). Check out past polls.

    Notices?