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
-
I've kept much the same logic as you show in your OP.
-
The wowN names you wanted are created and the hashes they refer to are easily accessible via a $master_hash{wowN} variable.
-
I've had to guess at input data as you didn't show any.
For demo purposes, I've used Inline::Files; for your real code, continue to use an array of filenames and open.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.