The understanding of passing references is REALLY important for OO-Perl. I have spent much time playing with all the possible syntaxes of referencing and de-referencing. I'm sure there are always more things to learn about the subject. But I suggest you all discover all you can.
Play with referenced multi-depth structures as much as possible. For example:
#!/usr/bin/perl -w use strict; sub FullStru { # creates the structures my $stru = { # an annonymous hash (ad hoc hash) Level2a => { # another ad hoc hash Level3a => ['a'..'z'], # an ad hoc list at +level 3 Level3b => [1..10] # another }, Level2b => [ qw(word1 word2 word3) ] # an ad hoc list +at level 2 }; return $stru; # notice that this is a reference to an annoymous ha +sh with sub levels } sub DownOne { my $ref = shift; # by using a reference, you get the whole enchila +da if ( ref($ref) eq 'HASH') { # return the elements as list. No real practical value other # than as an exercise.. at least as much as I can see return 'ref to HASH', values %$ref; } elsif (ref($ref) eq 'ARRAY') { # return the elements as a list return 'ref to ARRAY', @$ref; } elsif (ref($ref) eq 'SCALAR') { return 'ref to SCALAR', $$ref; } elsif ( not ref($ref)) { return 'not a ref'; } # and so on.. } my $X = FullStru(); # create the structure and return a pointer to it # first level my @results1 = DownOne($X); print join("\n",@results1),"\n"; shift(@results1); # get rid of that first element # second level my $elem; foreach $elem (@results1) { print "\n\t",join("\n\t",DownOne($elem)),"\n"; } # and so on.. you get the idea


The result should look like this:

ref to HASH HASH(0x1d5f518) ARRAY(0x1d5f548) ref to HASH ARRAY(0x22526c) ARRAY(0x1d5f488) ref to ARRAY word1 word2 word3

In reply to Re: Array Reference (Again) by perlcapt
in thread Array Reference (Again) by Ronnie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.