Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Arrays and hashes only with references

by grizzley (Chaplain)
on Mar 14, 2008 at 13:50 UTC ( [id://674203]=perltutorial: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    $arrayref = [1, 3, 5, 7];
    $hashref = {key1=>val1, key2=>val2, key3=>val3};
    
  2. or download this
    # want array element - use square brackets
    $value = $$arrayref[2];
    # want hash element - use curly brackets
    $othervalue = $$hashref{key2};
    
  3. or download this
    # array of arrays
    
    ...
    $$array_of_arrays[2].....
    # and there are 4 values in 'inner' level, so lets take last one:
    $value = $$array_of_arrays[2][3];
    
  4. or download this
    # hash of hashes
    
    ...
    $$hash_of_hashes{key22}.........
    # and end with 'inner' key
    $$hash_of_hashes{key22}{key4};
    
  5. or download this
    $monk1 = 'Jack';
    $monk2 = 'John';
    ...
    # see how it looks and where monks reside:
    use Data::Dumper;
    print Dumper $monastery;
    
  6. or download this
    # using @ in join function
    $arrayref = $$monastery{'garden'}{'plants'};
    ...
    
    # monk sitting in church -> in left nave -> in first bank -> as first
    print "Monk: ", $$monastery{'church'}{'left nave'}[0][0], "\n";
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-26 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found