Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How can I sort my array numerically on part of the string? (alias)

by LanX (Saint)
on Dec 02, 2020 at 13:27 UTC ( [id://11124516]=note: print w/replies, xml ) Need Help??


in reply to How can I sort my array numerically on part of the string?

> which has the added detriment of dropping off my animals...

maybe it has been mentioned before, but I can't seem to find it.

$a and $b are aliases of @list elements so $a=~s/,.+// will alter the original list.

That's why tybalt89 added an /r modifier in his solution

Actually I can't think of a useful application of aliasing in sort because elements are accessed multiple times in unpredictable ways.

DB<93> $x=0; @list=a..d DB<94> x sort { $x++; ($a.=$x) cmp ($b.=$x) } @list 0 'a13' 1 'b14' 2 'c234' 3 'd2' DB<95> x @list 0 'a13' 1 'b14' 2 'c234' 3 'd2' DB<96>
any useful application???

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-29 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found