in reply to How to test for a new line

If you only need the first line ... then only grab the first line:

my $line = <FILEPTR>;
But like dragonchild requested, we can't really help you completely unless we know more.

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)

Replies are listed 'Best First'.
Re^2: How to test for a new line
by BadMojo (Novice) on May 13, 2005 at 15:14 UTC
    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.

      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)
      
      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>;