Hi All,
I swear I've called subroutines this way before, but I can't find any
examples.
In this case, I'm looking to build some time/date functions. Regardless of
what the actual code is supposed to do, the calling of subroutines as
elements of a hash is causing me grief. I am receiving the following
message:
Undefined subroutine &main:: called at D:
\perldev\workroom\dates\dates.pl line 16.
Here is the code. Can anyone see what I am doing wrong here???
TIA,
Peter
P.S. you can see where I comment out the ccyymmdd_now function. That
approach works, but is not what I'm shooting for.
%date_formats = (
# "ccyymmdd" => {now => \ccyymmdd_now()},
"ccyymmdd" => {now => sub {
my @arr = localtime();
1900 + $arr[5] . sprintf("%02d",$arr[4] + 1) .
sprintf("%02d",$arr[3]);
}
},
"yyyymmdd" => {now => ${$formats{"ccyymmdd"}}{now},},
);
sub now {
my $format = shift;
$format =~ tr/A-Z/a-z/;
if (exists $date_formats{$format}){
# Not working...
&{${$date_format{$format}}{now}}();
}else{
print STDERR "invalid format\n";
}
}
#print "|" . ccyymmdd_now() . "|\n";
print "|" . now("ccyymmdd") . "|\n";
<STDIN>;
sub ccyymmdd_now{
my @arr = localtime();
1900 + $arr[5] . sprintf("%02d",$arr[4] + 1) . sprintf
("%02d",$arr[3]);
}
__END__
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]