g_speran has asked for the wisdom of the Perl Monks concerning the following question:
Good Evening Perl Monks, How can one assign the contents of an array within a multi-dimensional array to a set of variables passed to a subroutine?
use warnings; use Data::Dumper; my @arr; $arr[0][4] = (["S","M","R","B"]); print Dumper @arr; my ($VAR1,$VAR2,$VAR3,$VAR4) = @{$arr[0][4]}; print "Var1: $VAR1\tVar2: $VAR2\tVar3: $VAR3\tVar4: $VAR4\n"; Testing($arr[0][4]); sub Testing () { my ($VAR5,$VAR6,$VAR7,$VAR8) = @{$_}; print "Var5: $VAR5\tVar6:$VAR6\tVar7: $VAR7\tVar8: $VAR8\n"; }
OUTPUT ================= main::Testing() called too early to check prototype at C:\temp\arr_ref +ernce.pl line 11. $VAR1 = [ undef, undef, undef, undef, [ 'S', 'M', 'R', 'B' ] ]; Var1: S Var2: M Var3: R Var4: B Use of uninitialized value $_ in array dereference at C:\temp\arr_refe +rnce.pl line 14. Use of uninitialized value $VAR5 in concatenation (.) or string at C:\ +temp\arr_refernce.pl line 15. Use of uninitialized value $VAR6 in concatenation (.) or string at C:\ +temp\arr_refernce.pl line 15. Use of uninitialized value $VAR7 in concatenation (.) or string at C:\ +temp\arr_refernce.pl line 15. Use of uninitialized value $VAR8 in concatenation (.) or string at C:\ +temp\arr_refernce.pl line 15. Var5: Var6: Var7: Var8:
Expecting output ============== Var1: S Var2: M Var3: R Var4: B Var5: S Var6: M Var7: R Var8: B
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Assign valuse of array within array to variables
by LanX (Saint) on Feb 23, 2021 at 01:48 UTC | |
by g_speran (Scribe) on Feb 23, 2021 at 03:23 UTC | |
|
Re: Assign valuse of array within array to variables
by AnomalousMonk (Archbishop) on Feb 23, 2021 at 04:43 UTC | |
|
Re: Assign valuse of array within array to variables
by BillKSmith (Monsignor) on Feb 23, 2021 at 21:15 UTC |