Hello smknjoe,
As stevieb has shown, a hash is a much better option here. But, for the record, you need no strict 'refs' only if you’re not using eval — in which case, you also have to use package global variables (see perlref#Symbolic-references):
use strict; use warnings; our (@table_min_1, @table_min_2, @table_max_1, @table_max_2, $array_na +me); while (<DATA>) { chomp; if (/Array\s+(\w+)\s+(\d+)/) { $array_name = 'table_' . $1 . '_' . $2; } else { no strict 'refs'; my @fields = split /\s+/; push @$array_name, $fields[1]; } } print "\n"; print "$_ " for @table_max_1, @table_max_2, @table_min_1, @table_min_2 +; print "\n"; __DATA__ ...
On the other hand, if you are using eval, you can use strict without qualification, along with my lexicals:
use strict; use warnings; my (@table_min_1, @table_min_2, @table_max_1, @table_max_2, $array_nam +e); while (<DATA>) { chomp; if (/Array\s+(\w+)\s+(\d+)/) { $array_name = '@table_' . $1 . '_' . $2; # ^ } else { my @fields = split /\s+/; eval qq(push $array_name, "$fields[1]"); } } print "\n"; print "$_ " for @table_max_1, @table_max_2, @table_min_1, @table_min_2 +; print "\n"; __DATA__ ...
Note the additional @ in the second example. In both cases, the output is as desired:
15:43 >perl 1283_SoPW.pl a b c 1 2 3 d e f 4 5 6 15:43 >
But, again, don’t do that! :-)
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Soft Array Refs
by Athanasius
in thread Soft Array Refs
by smknjoe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |