: $self->{DF_SPEC} = {
: ...
:         c       => "$self->{DF_SPEC}{a} ...",
: 
: };
: 
: print "$self->{DF_SPEC}{'b'}\n";
: print "$self->{DF_SPEC}{'h'}\n";
: 
: 
: Produces the output:
: (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)
: <blank line>
: 
: Any ideas ?

You're trying to use parts of the $self->{DF_SPEC} hashref before the
hashref has been created. Also, the hashref $self is not the same as
the hash %self.  "use strict;" would have caught both of these errors.

My I suggest that you try something like this?:

my $shortDayName   = '(Mon|Tue|Wed|Thu|Fri|Sat|Sun)';
my $longDayName    = '(Monday|Tuesday|Wednesday|Thursday|Friday)';
my $shortMonthName = '(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)';
my $longMonthName  = 
'(January|February|March|April|May|June|July|August|September|October|November|December)';
my $dayNumber      = '([ 12][1-9]|10|20|30|31)';
my $hour           = '([01][0-9]|2[0-3])';
my $minute         = '([0-5][0-9])';
my $second         = '([0-5][0-9])';

# etc.

my $self;

$self->{DF_SPEC} = {
        a => $shortDayName,
        A => $longDayName,
        b => $shortMonthName,
        B => $longMonthName,
        c => "$shortDayName $shortMonthName $dayNumber $hour:$minute:$second CUT 
$year",
        # etc.
};

Yes there's a lot of variable creation, but it's self-documenting and
less prone to errors, and the regex pieces can even be tested
individually. Building and maintaining complex regular expressions from
simpler ones is often easier than building each one from scratch.

-- tdk

Reply via email to