This is one of the interesting things in perl. When I 1st started with perl I was weirded out by this quirk. Pretty much you need to pass by reference, then deference it.
return @ary1, @ary2, @ary3; becomes:
return \@ary1, \@ary2, \@ary3.
Dereference:
my @aryref = &retary;
print ${$aryref[0]}[0]; #print 1st element of 1st array
As an alternate method to return non order dependent data consider using a hash:
my %hash;
$hash{ary1} = @ary1;
$hash{ary2} = @ary2;
$hash{ary3} = @ary3;
I've started return and receiving hashes in my subrou.. ahem, methods, as you now dont have to worry about the order in which you call them..
As a slight aside Data::Dumper is invaluable when you get the dereferencing blues with complex data structures:
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my @aoh;
$aoh[0] = { key => 'value'};
print Dumper(@aoh);
HTH's!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.