in reply to How to test for a new line

Did you try it? What happened? Was it helpful?

In other words, it would be very simple to set up a few test cases (you should have them anyways!) and see if it works as you hope.


  • In general, if you think something isn't in Perl, try it out, because it usually is. :-)
  • "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"

Replies are listed 'Best First'.
Re^2: How to test for a new line
by BadMojo (Novice) on May 13, 2005 at 15:08 UTC
    aaahhhh for any one else who may want to know how to do this I got it to work by doing this

    $myvar1 == "\n"

    BadMojo
    mford@badmojo.biz
    www.badmojo.biz

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

      Try 'eq' and you'll be better off.

      Oh - turn on warnings. You'll have found you're not doing what you think you're doing.


      • In general, if you think something isn't in Perl, try it out, because it usually is. :-)
      • "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"

      That's only working because whatever's in $myvar1 and "\n" both happen to evaluate to 0 in a numeric context. You really meant eq; see perldoc perlop.

      Update: Now if what you really mean is "is it a blank line with nothing but whitespace" you probably want $myvar1 =~ /^\s*$/

        if ($tfcont1 eq \n) nor if ($tfcont1 eq "\n") works any ideas?

        BadMojo
        mford@badmojo.biz
        www.badmojo.biz

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