R
Richard Gration
While trying to work out the syntax for building a dispatch table of
coderefs from strings in a database I had occasion to construct the
following:
#!/usr/bin/perl
use strict;
use warnings;
my $one = "mysub";
sub mysub {
print shift,"\n";
}
#1
{
no strict 'refs';
$one->('scalar');
}
#2
{
'mysub'->('string');
}
#3
{
my $subref = \&$one;
$subref->('subref');
}
This produces the output:
scalar
string
subref
If there was any further proof needed that Perl updates are received in a
back alley somewhere from some dude with red eyes who smells of sulphur
.... I mean, honestly !!! ;-)
And then there's my slight amazement that #1 needs "no strict 'refs'" and
#2 doesn't ...
Rich
coderefs from strings in a database I had occasion to construct the
following:
#!/usr/bin/perl
use strict;
use warnings;
my $one = "mysub";
sub mysub {
print shift,"\n";
}
#1
{
no strict 'refs';
$one->('scalar');
}
#2
{
'mysub'->('string');
}
#3
{
my $subref = \&$one;
$subref->('subref');
}
This produces the output:
scalar
string
subref
If there was any further proof needed that Perl updates are received in a
back alley somewhere from some dude with red eyes who smells of sulphur
.... I mean, honestly !!! ;-)
And then there's my slight amazement that #1 needs "no strict 'refs'" and
#2 doesn't ...
Rich