Oops, hit send by mistake. This problem all seems to be about mistakes...
Thanks to all who replied.
> You have three different hashes in use. Look:
I did indeed have 3 hash tables... Duh (Must have been Friday afternoon).
The central problem was calling '&{${$date_format{$format}}{now}}()'
i
Subject: Re: calling a subroutine as an element of a hash table...
|
>--|
Peter Farrar wrote:
> Hi All,
>
> I swear I've called sub
Peter,
#!/usr/bin/perl -w
use strict;
my %date_formats = (
ccyymmdd => { now => sub {
my @arr = localtime();
print 'Year ', 1900 + $arr[5] . ' Month '. sprintf("%02d",$arr[4] + 1)
. ' Day ' . sprintf("%02d",$arr[3]);
}
} );
& { $date_formats{ccyymmdd}{now} };
Same output as previous
Peter
I saw Jenda's note and I suggest the code needs simplification.
> 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 => s
Peter Farrar wrote:
> 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
From: "John W. Krahn" <[EMAIL PROTECTED]>
> Peter Farrar wrote:
> > 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 subrouti
Peter Farrar wrote:
>
> 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 causi