in reply to Re: trouble with @ in a regular expression
in thread trouble with @ in a regular expression

Is too (if it can look like an interpolable variable).

>perl -wMstrict -le "my $str='foo@bar'; if ($str =~ /@b/){ print 'No need to escape the @ in a regex'; } " Possible unintended interpolation of @b in string at ... Global symbol "@b" requires explicit package name at ... Execution of -e aborted due to compilation errors.

Replies are listed 'Best First'.
Re^3: trouble with @ in a regular expression
by ww (Archbishop) on Mar 30, 2012 at 12:30 UTC
    Good catch! + +

    Note that it's the invocation of strict and warnings (-w) that illuminates my error.

      Even with warnings and strictures, Perl is quite happy with an @ if it cannot possibly be a variable.

      >perl -wMstrict -le "my $s = 'foo@bar'; print 'No need to escape lone @ in regex' if $s =~ /@ bar/x; " No need to escape lone @ in regex