Hi I´am trying to learn Perl. I have a problem with creating an array and using references to use it in another subroutine.
Sample code:
#!/usr/bin/perl
use strict;
use warnings;
sub test {
my @a = ("a","b","c");
return \@a;
}
# code just for test, the reference would just be used in next subroutine
my $array = test();
my @arr = @array;
print "@arr\n"; # just for test
test2(@arr);
sub test2 {
my @array1 = @_;
foreach $values (@array1) {
# do things
}
}
The point is to use the array from the 1st sub in the second one.
----------------- V2 -------------------------
#!/usr/bin/perl
use strict;
use warnings;
test();
sub test {
my @a = ("a","b","c");
return \@a;
}
print "\@a\n";
test2(\@a);
sub test2 { (my $array1) = @_;
foreach my $values (@array1) {
print "$values\n";
}
}