C
ccc31807
Question: I would like to access the string value of the variable
names passed as arguments to a sub inside the sub.
The following stores a hash in a file named like
'HASH(0xdeadbeef).dat' but I would like to store the hash in a file
named like 'hashref1.dat'.
use Storable;
my $hashref1 = retrieve('hashref1.dat');
my $hashref2 = retrieve('hashref2.dat');
my $hashref3 = retrieve('hashref3.dat');
# extensive processing on $hashref1, $hashref2, and $hashref3
# ... then
save_hashes($hashref1, $hashref2, $hashref3);
exit(0);
sub save_hashes
{
foreach my $hashref (@_)
{
my $filename = sprintf("%s.dat", $hashref);
store($hashref, $filename);
}
}
I can do it by passing the arguments twice, once as a string and the
second time as a variable, like this:
save_hashes($hashref1,.'hashref1', $hashref2, .'hashref1',
$hashref3.'hashref1', );
and then in the sub use the even arguments as the hashref and the odd
arguments as the filename, but this strikes me as a problem that ought
not to be a problem.
Thanks, CC.
names passed as arguments to a sub inside the sub.
The following stores a hash in a file named like
'HASH(0xdeadbeef).dat' but I would like to store the hash in a file
named like 'hashref1.dat'.
use Storable;
my $hashref1 = retrieve('hashref1.dat');
my $hashref2 = retrieve('hashref2.dat');
my $hashref3 = retrieve('hashref3.dat');
# extensive processing on $hashref1, $hashref2, and $hashref3
# ... then
save_hashes($hashref1, $hashref2, $hashref3);
exit(0);
sub save_hashes
{
foreach my $hashref (@_)
{
my $filename = sprintf("%s.dat", $hashref);
store($hashref, $filename);
}
}
I can do it by passing the arguments twice, once as a string and the
second time as a variable, like this:
save_hashes($hashref1,.'hashref1', $hashref2, .'hashref1',
$hashref3.'hashref1', );
and then in the sub use the even arguments as the hashref and the odd
arguments as the filename, but this strikes me as a problem that ought
not to be a problem.
Thanks, CC.