develooper Front page | perl.beginners | Postings from February 2002

Re: Return multiple arrays

Thread Previous
From:
Frank
Date:
February 5, 2002 09:18
Subject:
Re: Return multiple arrays
Message ID:
20020205171812.GB28081@fysh.org
On Tue, Feb 05, 2002 at 11:09:03AM -0500, Brett wrote:
> my $arrayref1 = [1, 2, 3];
> 
> my ($arrayref2, $arrayref3) = sub2($arrayref1);
> 
> sub sub2 {
> 
> 	my($arrayref5, ...);
> 	my $arrayref1 = shift;
> 
> 	return $arrayref6, $arrayref7;
> }
---end quoted text---

A really nice piece of syntactic sugar, I like, is:

@a= qw/foo bar baz/;
@b= qw/1 2 3/;
@c=\(@a,@b);	# <-- this line ;o)

# @c is now an array of references to arrays.
# if you used Data::Dumper you'd see:

print Dumper \@c


$VAR1 = [
            [
	    'foo',
	    'bar',
	    'baz'
	    ],
	    [
	    '1',
	    '2',
	    '3'
	    ]
   ];

neat eh?

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About