in reply to Re^2: using sub routines and solving an issue i have with passing variables
in thread using sub routines and solving an issue i have with passing variables
Try that code with strictures (which you should always use: use strict; use warnings; - see The strictures, according to Seuss). It works without strictures because of some magic. That magic can make it very hard to write correct code and find errors when things go wrong.
You can achieve similar results by replacing the magic with a hash:
use strict; use warnings; my %arrays; push @{$arrays{awesome_array}}, 1 .. 5; for my $element(@{$arrays{awesome_array}}){ print "$element\n"; push @{$arrays{another_awesome_array}}, $element; } for my $arrayName (keys %arrays) { print "$arrayName: @{$arrays{$arrayName}}\n" }
Prints:
1 2 3 4 5 awesome_array: 1 2 3 4 5 another_awesome_array: 1 2 3 4 5
|
|---|