H
Henry Law
This doesn't seem to be a FAQ; I tried Googling but couldn't find a
suitable search string to get a manageable set of results ...
This is the core of my code:
#! /usr/bin/perl
use strict;
use warnings;
use Date::Calc qw(
Date_to_Text
);
my @LoL;
push @LoL, [2001,12,25,"foo"];
push @LoL, [2004,4,6,"bar"];
# Gives expected output
foreach my $lref (@LoL) {
print Date_to_Text($lref->[0],$lref->[1],$lref->[2]),"\n";
}
foreach my $lref (@LoL) {
# Fails with message "Use of uninitialized value in range (or flip)"
print Date_to_Text( $lref->[0..2] ), "\n";
}
__END__
I expected $lref->[0..2] to be a slice consisting of the first three
elements of the array pointed to by $lref, i.e. the same as
($lref->[0],$lref->[1],$lref->[2])) but plainly it's not. In order to
get an array to pass to my subroutine am I condemned to coding the
elements separately, or is there a correct way of coding the slice?
Looking up flip-flops I can see that I've got some array-scalar
problem in the code, but I haven't been able to puzzle out what it is.
Can someone point me in the right direction?
Henry Law <>< Manchester, England
suitable search string to get a manageable set of results ...
This is the core of my code:
#! /usr/bin/perl
use strict;
use warnings;
use Date::Calc qw(
Date_to_Text
);
my @LoL;
push @LoL, [2001,12,25,"foo"];
push @LoL, [2004,4,6,"bar"];
# Gives expected output
foreach my $lref (@LoL) {
print Date_to_Text($lref->[0],$lref->[1],$lref->[2]),"\n";
}
foreach my $lref (@LoL) {
# Fails with message "Use of uninitialized value in range (or flip)"
print Date_to_Text( $lref->[0..2] ), "\n";
}
__END__
I expected $lref->[0..2] to be a slice consisting of the first three
elements of the array pointed to by $lref, i.e. the same as
($lref->[0],$lref->[1],$lref->[2])) but plainly it's not. In order to
get an array to pass to my subroutine am I condemned to coding the
elements separately, or is there a correct way of coding the slice?
Looking up flip-flops I can see that I've got some array-scalar
problem in the code, but I haven't been able to puzzle out what it is.
Can someone point me in the right direction?
Henry Law <>< Manchester, England