my @dates = qw(2Jul2001 21Jul2001);
for my $date (@dates)
{
my ($month, $day, $year) =
length $date == 8 ?
unpack 'AA3A4', $date :
unpack 'A2A3A4', $date;
print "M: ", $month, "\tD: ", $day, "\tY: ", $year, "\n";
}
Unpack works well with fixed format data like this.
Luke
On Tue, 3 Jul 2001 [EMAIL PROTECTED] wrote:
>
> Hi.
>
> My file has dates in it that either come out as "2Jul2001" or "21Jul2001". So one
>or two digits for the day, three for the month, and four for the year.
>
> So I would like to split out the day, month, year, and am interested in splitting
>techniques, where there are no delimeters.
>
> Of course, I could just test the length and then use substr it all out, or even
>sprintf it into a new variable with a pad at the first character.
>
> But this is perl, and I reckon there are much cooler ways to do it.
>
> Any takers?
>
> Paul.
>
>
>
> ------------------------------------------------
> Global WebMail -
> Delivered by Global Internet www.global.net.uk
> ------------------------------------------------
>
>