in reply to Re^5: Checking input
in thread Checking input

I disagree. Consider the code:

#!/usr/bin/perl $foo = "this is a \\ test"; print "Foo: ($foo)\n"; ($bar) = $foo =~ /([\-])/; print "Bar: ($bar)\n";
By your reasoning $bar should be '\'. It isn't. This script prints
Foo: (this is a \ test) Bar: ()

Change $foo to "this is a \\ test - " and $bar becomes '-', not '\'. The \ before the - in the character class [\w\-] isn't escaping anything, true. But it doesn't get added to the character class.

Replies are listed 'Best First'.
Re^7: Checking input
by diotalevi (Canon) on Feb 25, 2003 at 23:46 UTC
      My whole point was that something like [a-] looks like it is a typo on the programmer's part. If I saw this in a script my first question would be "Did you mean something like [a-z]?" If I saw [-a] it doesn't look like a typo. Nor does [a\-] look like a typo. I can't really explain it any more clearly than this.

      And I should note that this is a lot more trouble than I thought it would be. ;) Such a simple question shouldn't ever have to go to a Re^7...