in reply to How to parse text file with clear delimiters: regex? split?

How about this?
#!/usr/bin/perl { local $/ = "-----\n"; while(my $note = <DATA>) { my($month, $day, $year, $time, $body) = $note =~ m#^(\d{2})/(\d{2})/(\d{4})\s+(\d{2}:\d{2})\s*\n(.*)#s; } } __DATA__ 04/01/2002 19:57 FOOBARS >>my favorite candy by far! yummy! ----- 04/03/2002 07:34 Ooh, it looks as if it might rain tomorrow. note to self {buy buy buy!} ----- 04/12/2002 12:02 Energy X invasion point++ ----- 04/12/2002 12:56 Crisis resolved (that was fun!) -----

Replies are listed 'Best First'.
Re: Re: I need help parsing this text file!
by Kanji (Parson) on Apr 02, 2002 at 02:19 UTC

    If you (ab)use split's ability to limit the number of fields it splits something into, you can do away with the regexp for something a little cleaner...

    my($m,$d,$y,$t,$b) = split /[ \/\n]/ => $note, 5;

        --k.


Re: Re: I need help parsing this text file!
by belg4mit (Prior) on Apr 02, 2002 at 01:29 UTC
    good use of $/ {slaps self with trout}

    --
    perl -pe "s/\b;([st])/'\1/mg"