in reply to Hints for getting this perly...
to(my $date) = grep m%\w+, \w+ \d\d, \d\d\d\d%, @file; $date =~ m%\w+, (\w+ \d\d, \d\d\d\d)%;
If the regex doesn't match, it returns an empty list, so it'll disappear from the results.my($date) = map m%\w+, (\w+ \d\d, \d\d\d\d)%, @file;
Also, if the files are largish and the date always appears near the top, I'd avoid reading in the whole file and just read in, say, the first k of text, as a single string. Then you don't even need map.
local $/ = \1024; my $begin = <F>; my ($date) = $begin =~ m%\w+, (\w+ \d\d, \d\d\d\d)%; my $time = str2time($date);
update Thanks to Animator for the hint... You do appear to need the entire file. I don't know what is eeasier, checking the file line by line, as you do, or reading in the whole file as a single string, and processing it that way.
You can achieve that by undeffing $/ instead:
undef $/;
I think, for this specific file format, your way is easier.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Hints for getting this perly...
by hynek (Novice) on May 11, 2005 at 09:16 UTC |