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.
In reply to Re: Hints for getting this perly...
by bart
in thread Hints for getting this perly...
by hynek
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |