in reply to Re: regular expression with @@/
in thread regular expression with @@/
Actually, in this particular case, it should work with and without quoting, because /@@/ doesn't interpolate anything (as opposed to /@@x/ or /\Q@@x\E/, for example).
#!/usr/bin/perl use warnings; use strict; $_ = 'foo@@bar'; print "matched\n" if /@@/; print "matched\n" if /\Q@@\E/; print "matched\n" if /\@\@/; __END__ matched matched matched
Update: maybe a better (anchored) check, avoiding the potential gotcha of matching against a single-@ pattern:
#!/usr/bin/perl use warnings; $_ = '@@'; print "1 matched\n" if /^@@\z/; print "2 matched\n" if /^\Q@@\E\z/; print "3 matched\n" if /^\@\@\z/; print "4 matched\n" if /^\Q@@x\E\z/; # doesn't match, because @x is be +ing interpolated print "5 matched\n" if /^@\@x\z/; # doesn't match, because there is + no 'x' in the string __END__ Possible unintended interpolation of @x in string at ./811585.pl line +10. Name "main::x" used only once: possible typo at ./811585.pl line 10. 1 matched 2 matched 3 matched
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: regular expression with @@/
by BioLion (Curate) on Dec 08, 2009 at 11:26 UTC |