Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Simplifying for loop and applying multiple push function

by Roy Johnson (Monsignor)
on Dec 14, 2005 at 20:53 UTC ( [id://516761]=note: print w/replies, xml ) Need Help??


in reply to Simplifying for loop and applying multiple push function

You're not going to be able to do it sensibly in one line. You can get rid of the loop and do it in two statements, though:
push @one, values %hash; push @two, keys %hash;

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Simplifying for loop and applying multiple push function
by xdg (Monsignor) on Dec 14, 2005 at 20:59 UTC

    Great solution! And if anyone else was wondering, yes, these will both be properly ordered:

    From keys:

    The keys are returned in an apparently random order. The act +ual random order is subject to change in future versions of perl +, but it is guaranteed to be the same order as either the "val +ues" or "each" function produces (given that the hash has not bee +n modified).

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re^2: Simplifying for loop and applying multiple push function
by VSarkiss (Monsignor) on Dec 14, 2005 at 21:22 UTC
      That's only the same if @one and @two started out empty.

      Caution: Contents may have been coded under pressure.
        Why does it matter whether @one or @two are empty beforehand? Won't the status of the hash and the arrays be identical regardless?

Log In?
Username:
Password:

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

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

    No recent polls found