Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Will the sorting order of an array used in producing new arrays be retained?

by AnomalousMonk (Abbot)
on Oct 09, 2012 at 22:24 UTC ( #998095=note: print w/ replies, xml ) Need Help??


in reply to Will the sorting order of an array used in producing new arrays be retained?

For question 1: In general, WRT grep (which can only remove elements): yes, the relative order is maintained. For Far More Than You Ever Wanted to Know about this, see the recent Order in which grep/map receive elements.

For question 2: In general, WRT map (which is allowed to insert elements) the answer is no:

>perl -wMstrict -le "my @sorted = (1, 2, 3, 4, 5, 6); my @unsorted = map { $_, 99 } @sorted; print qq{@unsorted}; " 1 99 2 99 3 99 4 99 5 99 6 99


Comment on Re: Will the sorting order of an array used in producing new arrays be retained?
Download Code
Re^2: Will the sorting order of an array used in producing new arrays be retained?
by jospan (Novice) on Oct 09, 2012 at 22:56 UTC
    Thank you both for the quick reply - I appreciate it!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2015-07-05 14:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls