Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello fellow programmers, I was wondering if anyone could tell me why i seem to be able to use this syntax :
if (($words[1] eq 0) or ($words[1] =~ /s_/) or ($words[1] =~ /jkbrb/) or ($words[1] =~ /adiode/) or ($words[1] =~ /jkbrb/) or ($words[1] =~ /buftd/) or ($words[1] =~ /bh01d1/) or ($words[1] =~ /cload1/))
but not this line:     if ($words[1] =~ /^\/) is "\" a special character? is there any way to make it so that i can use it? quotes? etc? i had thought about parsing through and removing the first letter of the string and storing it-- then going through and seeing if they were "\"'s. But i wasn't sure if it would give me the same problem. THANK YOU FOR YOUR HELP!!!

Edit: chipmunk 2001-06-18

Replies are listed 'Best First'.
Re: is "/" a special character when using substrings??
by runrig (Abbot) on Jun 19, 2001 at 01:27 UTC
    It is a 'special' character when in double quotes or in regular expressions. In those cases you need two backslashes. And see perldoc perlre.

      Don't forget that \ is also special inside single quotes. It is special in all of Perl's quote-like operators except for qw() and single-quoted here-docs (so that adds qx(), tr///, and double-quoted and back-quoted here-docs). (updated)

              - tye (but my friends call me "Tye")
        I'm going to assume that this is true of at least 5.6 and beyond, or that I'm finding a bug here:
        C:\>perl -v This is perl, version 5.005_02 built for MSWin32-x86-object ... C:\>perl print 'hello\n'; print "hello\n"; ^D hello\nhello C:\>

        Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
Re: is "/" a special character when using substrings??
by dimmesdale (Friar) on Jun 19, 2001 at 01:45 UTC
    runrig is right. For a fix for more chars that are special, though, a \Q...\E sequence is more pleasing to the eye than hundreds of \\'s, to further answer your question.