in reply to Re^2: handling erronous input
in thread handling erronous input

You've missed part of the regexp out (the bit that captures comments) and missed a backslash out (from \d{5}). It looks like you don't know that, in a regexp, parentheses capture their matches into $1, $2, $3 etc. Again, see perlretut and perlre for the details.

Your code is similar to mine. You use

while ( ... ) { unless ( some-condition ) { next } some-code }

while I prefer the equivalent

while ( ... ) { if ( some-condition ) { some-code } }

it's just that (IMHO) yours is harder to read (and longer, too)

That said, you can use my code with a filehandle like so (I've rearranged it a bit to use unless and made the regexp a more lenient towards spaces)...

while ( <DATAFILE> ) { chomp; unless ( m{^ (\d\.\d{5}) \s*,\s* (\d\d:\d\d:\d\d) \s* (.*) $ }x ) +{ next } my ( $quote, $time, $comment ) = ( $1, $2, $3 ); # captures my ( $hours, $minutes, $seconds ) = split /:/, $time; #do something with $quote, $hours, $minutes, $seconds & $comment }

Replies are listed 'Best First'.
Re^4: handling erronous input
by GrandFather (Saint) on Apr 06, 2008 at 23:35 UTC

    I prefer:

    while ( ... ) { next if some-condition; some-code }

    which not only saves a couple of (trivial I admit) lines of code, it reduces clutter and avoids an extra level of nesting for some-code.


    Perl is environmentally friendly - it saves trees
Re^4: handling erronous input
by Conal (Beadle) on Apr 06, 2008 at 23:50 UTC
    gotcha.. i understand completely now.

    thanks again, and its works fine, i just wanted to be certain before i messed anything up.. fwiw here is a link to my project --> http://fxr.freehostia.com/pam/pam_alpha_5.php

    and sorry for my wanton abuse of floating point numbers. ;p

    conal.