in reply to Test for newline

You're using $discovered$i, which is isn't an array element, but an awkwardly constructed scalar variable name. You might want to look into using a real array instead.

If you want to check if the value of a variable equals the newline character, just use $variable eq "\n" as a test, there's no need to use a regex.

And, of course, $foo =~ "pattern" isn't a regular expression match. I'm not quite sure why it isn't a syntax error, but it's certainly wrong. $foo =~ /pattern/ is probably what you mean.

Replies are listed 'Best First'.
Re^2: Test for newline
by BUU (Prior) on Feb 19, 2005 at 09:23 UTC
    While your first two points are correct, I'm afraid I must point out that your third point is incorrect.

    $foo =~ "pattern" is mostly certainly a regular expression match, with the expression "pattern" being applied to the variable $foo. The =~ operator will accept anything that may be stringified as it's right hand side, which is really what a regex is, // are just fancy quotes that have slightly different semantics.
      Interesting, thanks for pointing that out!

      I wouldn't recommend using $string =~ "...", though, it's confusing to beginners. Imagine if someone writes "\w" and wonders why it behaves differently than /\w/.

Re^2: Test for newline
by holli (Abbot) on Feb 19, 2005 at 09:42 UTC
    He uses $discovered[$i], but because there are no code-tags the brackets are interpreted as a link.


    holli, /regexed monk/