V
Vito Corleone
Hi,
I tried to make a call a function by reference. Here is the code:
#!/usr/bin/perl
use strict;
sub show_a {
my ($txt) = @_;
print "show_a: $txt\n\n";
}
sub show_b {
my ($txt) = @_;
print "show_b: $txt\n\n";
}
sub show {
my ($type) = @_;
my $f = "show_" . $type;
$f->($type);
}
show("a");
But there was an error:
Can't use string ("show_a") as a subroutine ref while "strict refs" in
use at ./test.pl line 18.
How do I make this kind of call to function with 'use strict' turned on?
--Vito
I tried to make a call a function by reference. Here is the code:
#!/usr/bin/perl
use strict;
sub show_a {
my ($txt) = @_;
print "show_a: $txt\n\n";
}
sub show_b {
my ($txt) = @_;
print "show_b: $txt\n\n";
}
sub show {
my ($type) = @_;
my $f = "show_" . $type;
$f->($type);
}
show("a");
But there was an error:
Can't use string ("show_a") as a subroutine ref while "strict refs" in
use at ./test.pl line 18.
How do I make this kind of call to function with 'use strict' turned on?
--Vito