in reply to regex question

you also don't escape characters in a character class. your regex (once g is added for global) will strip back slash characters, as well as braces. i.e. should be:
$var =~ s/[()]//g;
the hardest line to type correctly is: stty erase ^H

Replies are listed 'Best First'.
Re^2: regex question
by Perl Mouse (Chaplain) on Oct 27, 2005 at 15:09 UTC
    you also don't escape characters in a character class. your regex (once g is added for global) will strip back slash characters, as well as braces.
    No, it doesn't. There's no need to escape the parens, but it certainly doesn't do any harm:
    $_ = 'foo\bar(baz)'; print "Before: '$_'; "; s/[\(\)]//g; print "After: '$_'\n"; __END__ Before: 'foo\bar(baz)'; After: 'foo\barbaz'
    No backslashes are removed.
    Perl --((8:>*
Re^2: regex question
by sauoq (Abbot) on Oct 27, 2005 at 22:58 UTC
    you also don't escape characters in a character class.

    That's not very good advice. Sometimes you certainly do need to escape characters in a character class. Take the following for example:

    $ perl -le '$_ = q/f!o@o#b$a%r^b&a*z/; s/[!@#$%^&*]//g; print'

    -sauoq
    "My two cents aren't worth a dime.";
    
      Or, even more drastical, see the difference in these lines:
      perl -e '$_="bjzu-sbtz -abnzo-tbhze-rb zp-ebrzl- bhza-cbkze-r\n";s/[b-z]//g;print'
      vs.
      perl -e '$_="bjzu-sbtz -abnzo-tbhze-rb zp-ebrzl- bhza-cbkze-r\n";s/[b\-z]//g;print'

      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re^2: regex question
by Juerd (Abbot) on Oct 27, 2005 at 19:02 UTC

    the hardest line to type correctly is: stty erase ^H

    Type it as: stty erase ^V^H

    Update: I missed the point, which was that you cannot backspace if backspace isn't set correctly.