Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Can't figure out the realtive ordering.

by duyet (Scribe)
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 making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2014-09-22 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (191 votes), past polls