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

Re: Regular expressions and sort

by Fletch (Bishop)
on Nov 04, 2005 at 13:56 UTC ( [id://505698]=note: print w/replies, xml ) Need Help??


in reply to Regular expressions and sort

Erm, why not just use an ST and do the matching once and not worry about clobbering $1 et al. More efficient to boot.

my @result = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { /_(\d{2})_/; [ $_, $1 ] } @f;

Replies are listed 'Best First'.
Re^2: Regular expressions and sort
by zaro (Novice) on Nov 04, 2005 at 14:14 UTC
    Thanks, your solution seems better. I will use it :-).
    But it still doesn't explain the strange behaviour of m//.

      No, because perldoc perlre explains that:

      The numbered variables ($1, $2, $3, etc.) and the related punctuation set ($+, $&, $`, $', and $^N) are all dynamically scoped until the end of the enclosing block or until the next successful match, whichever comes first. (See "Compound Statements" in perlsyn.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-26 08:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found