in reply to Hints for getting this perly...

You can try map instead of grep, and just keep the matches. From
(my $date) = grep m%\w+, \w+ \d\d, \d\d\d\d%, @file; $date =~ m%\w+, (\w+ \d\d, \d\d\d\d)%;
to
my($date) = map m%\w+, (\w+ \d\d, \d\d\d\d)%, @file;
If the regex doesn't match, it returns an empty list, so it'll disappear from the results.

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
    Well, I've just put it also into the while loop. d'oh

    As you might see, the development of this tiny script was pretty....evolutionary so it's full of strange artifacts. :)

    Regarding the update, I also played with the undef $\-idea however now when considering "..." it might really pay off.