G'day lightoverhead,
As has already been pointed out, using symbolic references this way is a bad idea. If you're interested purely for academic reasons, see "perlref: Symbolic references"; understanding the refs stricture of the strict pragma would also be useful.
As an alternative, consider the technique in this script (and see the Notes at the end):
#!/usr/bin/env perl use strict; use warnings; use Inline::Files; my %master_hash; my @filehandles = (\*FILE1, \*FILE2, \*FILE3); for (0 .. $#filehandles) { my $fh = $filehandles[$_]; my $wow_key = "wow$_"; while (<$fh>) { chomp; push @{$master_hash{$wow_key}{(split /\t/)[1]}}, 'sth'; } } use Data::Dump; dd \%master_hash; __FILE1__ x file1line1 x file1line2 __FILE2__ x file2line1 x file2line2 __FILE3__ x file3line1 x file3line2
Output:
{ wow0 => { file1line1 => ["sth"], file1line2 => ["sth"] }, wow1 => { file2line1 => ["sth"], file2line2 => ["sth"] }, wow2 => { file3line1 => ["sth"], file3line2 => ["sth"] }, }
Notes
-- Ken
In reply to Re: How to correctly use a symbolic reference to automatically generate hash names?
by kcott
in thread How to correctly use a symbolic reference to automatically generate hash names?
by lightoverhead
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |