Am I the only one that is still having a problem with references? No matter how much information I read about them, they are still out of my reach. I just finished perlref and I'm still having problems with them.

While looking at Crian's post, I'm having trouble getting the second example to work (the first one works correctly) but the second (the second "f" sub) does not print at all.

Am I doing something wrong, or did I overlook something? I copied & pasted his code directly (changing the second "f" subroutine to a "g" for clarity) but it does not work for me.

This is my first programming language so I don't have any other syntax I can fall back on to make sure I am doing these correctly. Coincedently, as I try to pick up C++, I'm also having problems with references. Are there any other good (beginner) tutorials or books on references that I've overlooked?

Ultimately, I would like to pass a couple of arrays to a subroutine compare them, do some other calculations and return multiple arrays back
Something like this:

my @array1 = (0..9); my @array2 = ('a'..'l'); (@a1, @a2) = &f(\@array1, \@array2); print "\@a1 is: @a1\n"; print "\@a2 is: @a2\n"; sub f { my @a1 = @{shift}; my @a2 = @{shift}; ... return (\@a1, \@a2); }

Thanks


In reply to Help with references by coldmiser

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.