Re: date format
- From: "Bart Van der Donck" <bart@xxxxxxxxxx>
- Date: 5 Jul 2006 03:57:48 -0700
Ian Wilson wrote:
Bart Van der Donck wrote:
[...]
#!perl
use strict;
use warnings;
my $file =
'%%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006
%%%%%%%%%%%%
1111111111111111111111
2222222222222222222222
3333333333333333333333
';
my @m = ('Jan', 'Feb', 'Mar', 'Apr', 'May',
'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
my @ar = split / /, (split /\n/, $file)[0];
$ar[3] =~ s/$m[$_]/@{[sprintf('%02g',$_+1)]}/ for (0..$#m);
die "Can't find month '$ar[3]'\n" unless $ar[3]=~/^(0|1)[0-9]$/;
print $ar[7], $ar[3], sprintf('%02g',$ar[4]);
__END__
Hope this helps,
I'm not a beginner and I found this example rather obscure and hard to
understand. Perl needn't look that much like line noise IMO.
I think you've entered the domain of personal preferences here. As far
as I'm concerned, my code doesn't read as line noise (I can easliy
follow it, but hey, that's me).
I for one have more difficulty to follow Mr Krahn's code, as I'm not
too confident with some of his techniques... But I do think that his
code will be perceived as more obscure by a beginner when you juxtapose
it next to mine.
But of course I do like occasional "sport lines" like
$ar[3] =~ s/$m[$_]/@{[sprintf('%02g',$_+1)]}/ for (0..$#m);
in stead of splitting it up in 5 lines or so, like I would rather do in
production code. Just do myself a favour in the future :-)
I'd put the data in a DATA section since it gives a structure
'while(<>){}' that is closer to the way most peaple read data files.
I agree, that would have been better indeed.
I'd use meaningful variable names since the OP claims to be a beginner
(though I think they're a good idea no matter your level of experience)
$file = file
@ar short for array (which isn't descriptive for its content of course,
but the content of that array is not univocal here anyway)
@m short for @months
Well, yes, when written in full they would become more meaningful I
suppose...
[...]
--
Bart
.
- Follow-Ups:
- Terse vs didactic. Was Re: date format
- From: Ian Wilson
- Re: date format
- From: Tad McClellan
- Terse vs didactic. Was Re: date format
- References:
- date format
- From: spross
- Re: date format
- From: Bart Van der Donck
- Re: date format
- From: Ian Wilson
- date format
- Prev by Date: Re: ReadKey/ ReadLine query
- Next by Date: Re: Upgrade perl from 5.8.6 to 5.8.8 - help with upgrade
- Previous by thread: Re: date format
- Next by thread: Re: date format
- Index(es):
Relevant Pages
|