in reply to Re: How to test for a new line
in thread How to test for a new line

I need to know if its truly a new line or if they spanned multiple lines so i can give a understanable error to the user. I will try eq again

BadMojo
mford@badmojo.biz
www.badmojo.biz

!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-!
When something works but shouldn't thats BADMOJO baby.

Replies are listed 'Best First'.
Re^3: How to test for a new line
by jeffa (Bishop) on May 13, 2005 at 15:20 UTC

    You should have specified that in your original question. "... to be sure they only have new lines" is not the same as "give a understanable error to the user." Now then, here's how i might check for such an "error":

    my @array = <FILEHANDLE>; if (@array < 1) { # we have no lines, send an error message } eslif (@array > 1) { # we have a 'too many lines' error jim, send a message } else { # this porridge tastes *just* right ... continue with processing }
    When you slurp a filehandle into an array, you can always count the number of lines by counting how many elements the array has. No need to explicitly check for newlines.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re^3: How to test for a new line
by mrborisguy (Hermit) on May 13, 2005 at 15:24 UTC
    here's a thought... could you join all of the lines together (maybe chomp them all first), then you get one big line. then, you don't have to worry if the user's input spans into the second line or if they have new lines. this is assuming that a file contains only one 'line' of useful information though.
    my $line = join '', map { chomp } <FILEPTR>;