in reply to Re^3: How to return a two dimensional array from a function in Perl?
in thread How to return a two dimensional array from a function in Perl?
A version showing some variations of technique (tested under Perl 5.8.9):
The ListOfNames() function could simply be written as:c:\@Work\Perl\monks>perl -e "use warnings; use strict; ;; my @ListPeople = ListOfNames(); ;; PERSON: for my $counter (0 .. $#ListPeople) { my $ar_person = $ListPeople[$counter]; last PERSON if $ar_person->[0] eq ''; print qq{$counter. What is my Name: @$ar_person \n\n}; }; ;; sub ListOfNames { my @LON; ;; $LON[0][0] = 'Tim'; $LON[0][1] = 'O'; $LON[0][2] = 'Tay'; ;; $LON[1] = [ 'John', 'Fitz', 'Gerald' ]; ;; $LON[2] = [ qw(Gerald Fitz John) ]; ;; push @LON, [ '', 'not', 'here' ], [ 'Billy', 'Bob', 'Thornton' ]; ;; return @LON; } " 0. What is my Name: Tim O Tay 1. What is my Name: John Fitz Gerald 2. What is my Name: Gerald Fitz John
sub ListOfNames { return [ 'Tim', 'O', 'Tay' ], [ 'John', 'Fitz', 'Gerald' ], [ qw(Gerald Fitz John) ], [ '', 'not', 'present' ], [ 'Billy', 'Bob', 'Thornton' ], ; }
Give a man a fish: <%-{-{-{-<
|
|---|