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

Re: Can't figure out the realtive ordering.

by duyet (Monk)
on Sep 26, 2011 at 06:26 UTC ( #927797=note: print w/ replies, xml ) Need Help??


in reply to Can't figure out the realtive ordering.

The order of an array is fixed, eg. $alex[1] is always 44. The order of an hash is not fixed! See perlintro for more info about hash/array.

You should use strict and warning in your code. There is an error in the code: $heather('joe') should be $heather{'joe'}, since you defined an hash %heather but there is no array @heather

Use Dumper to look at the data.

use strict; use warnings; use Data::Dumper; my @alex = ( fred => 44, 'joe' => 2983, mike => -94 ); print Dumper( \@alex ); my %heather = ('This', 'will', 'actually', 'work'); print Dumper( \%heather ); %heather = @alex; print Dumper( \%heather ); print "C: [$heather{'fred'}] [$heather{'mike'}] [$heather{'joe'}] ", " +[$heather{'This'}]\n"; $heather{'dingbat'} = 33; $heather{'giggles'} = 870; print Dumper( \%heather ); @alex = %heather; print Dumper( \@alex ); print "D: @alex\n";


Comment on Re: Can't figure out the realtive ordering.
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2015-07-04 01:09 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 (57 votes), past polls