big_cheese
07-28-2006, 03:06 AM
Hi,
Can I pass references of hashes (like \%h) to subroutines and have the subroutine create new keys and values for the hash (%h)? From the documentation it seems possible, but I cannot do it.
This is a summary of my Code
The &read subroutine reads a data file "GC2.lis" and creates new keys values for three hashes
&read("GC2.lis", \%nom, \%slow, \%fast);
sub read {
die "Cannot open file '$_[0]': $!" unless (open READ, $_[0]);
foreach $i (2..4) {
LOOP: while (<READ>) {
if (/^\s+(\S+)\s+(\S+)\s*$/) {
${$_[$i]}{$1} = $2;
}
elsif (/^y$/) {
last LOOP;
}
}
}
close READ;
return;
}
Thanks in advance for your help. Glad I could join.
Can I pass references of hashes (like \%h) to subroutines and have the subroutine create new keys and values for the hash (%h)? From the documentation it seems possible, but I cannot do it.
This is a summary of my Code
The &read subroutine reads a data file "GC2.lis" and creates new keys values for three hashes
&read("GC2.lis", \%nom, \%slow, \%fast);
sub read {
die "Cannot open file '$_[0]': $!" unless (open READ, $_[0]);
foreach $i (2..4) {
LOOP: while (<READ>) {
if (/^\s+(\S+)\s+(\S+)\s*$/) {
${$_[$i]}{$1} = $2;
}
elsif (/^y$/) {
last LOOP;
}
}
}
close READ;
return;
}
Thanks in advance for your help. Glad I could join.