in reply to Re: Search and Replace Within Subscopes
in thread Search and Replace Within Subscopes

Looks good, but some of the syntax is a bit alien to me (in particular the use of [] and {} in '$x=~ s.{.}smge' Is there a good text/url on this kind of syntax?
  • Comment on Re^2: Search and Replace Within Subscopes

Replies are listed 'Best First'.
Re^3: Search and Replace Within Subscopes
by toolic (Bishop) on Jul 04, 2008 at 16:55 UTC
    Those are alternate delimeters. See the "substitution operator" in perlop. Also read perlre. There is a wealth of information on perldoc.perl.org.
Re^3: Search and Replace Within Subscopes
by jethro (Monsignor) on Jul 04, 2008 at 16:56 UTC
    You can use any pair of non-alphanumeric, non-whitespace charaters as delimiters of a regex pattern. So these regexes are equivalent:

    s/a/b/; s"a"b"; s^a^b^; s{a}{b}; s(a)[b];
    Only ' is an exception, this character prevents variable interpolation if used as delimiter

    Advantage is that you can use / inside them without escaping the character. Also it could be argued that {} [] or () as delimiters just look better, especially for complex patterns. Edit: Deleted one erraneous example found by ikegami

      >perl -ce"/a/b/" Bareword found where operator expected at -e line 1, near "/a/b" (Missing operator before b?) syntax error at -e line 1, near "/a/b" -e had compilation errors.

      /a/b/
      is the same as
      m/a/ b /