Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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 lurking in the Monastery: (10)
As of 2014-12-26 11:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls