Hi folks,
I've got the code:
package Trainset;
my %_BLOCKS=(); # blocks of track
my %_TRAINS=(); # trains
my %_BOXS=(); # signalboxes
sub blocks { # Return list of blocks
sort keys %_BLOCKS;
}
sub trains { # Return list of trains
sort keys %_TRAINS;
}
sub boxes { # Return list of signalboxes
sort keys %_BOXS;
}
I wanted to eliminate the duplicated code so I wrote:
sub list {
my $self=shift;
my $key=uc(shift);
print "using '_$key' as hash name\n";
return sort keys %${"_$key"};
}
which according to the section of symbolic references in perldoc perlrefs
should work. However, while Trainset->blocks returns the list,
Trainset->list('blocks') doesn't.
Can anyone spot the problem or suggest an alternative please.
--
Gary Stainburn
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>