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

My apologies if this is a nobrainer, I need a fast answer, and my chatterbox has gone offline...

I seem to recall Perl used to support all forms of delimiters on regular expressions. (Am I wrong?)
I suppose the reason is Version 8 RegExp, does anyone know where I can find a good explanantion
for its design &| the reason it was chosen?

--- perchance
The Lifting

Replies are listed 'Best First'.
Re: RegExp Delimiter
by tadman (Prior) on Sep 03, 2002 at 07:00 UTC
    It supports a bunch of them, basically anything you can dream up:
    s/.../.../ s#...#...# s<...><...> s[...][...] s:...:...: s;...;...;
    The same sort of rules apply to things like qr, qw, qq and qx. This gives you the freedom to choose something that won't collide.

    On that note, though, the following seems to be valid Perl code, if a little awkwardly:
    my $sql = qq{ SELECT id FROM ${table} };
    It works as far as I can tell, but my syntax hilighter goes nuts on it, closing the string at the first instance of '}', which makes sense. Perl seems to be extra careful about interpolating.
      On that note, though, the following seems to be valid Perl code, if a little awkwardly:
      my $sql = qq{ SELECT id FROM ${table} };
      It works as far as I can tell, but my syntax hilighter goes nuts on it, closing the string at the first instance of '}', which makes sense. Perl seems to be extra careful about interpolating.

      Perl takes balanced parens/brackets/braces/angles into account, that's why it works. Quoting from perlop:

          Non-bracketing delimiters use the same character fore and aft, but the
          four sorts of brackets (round, angle, square, curly) will all nest,
          which means that
      
                  q{foo{bar}baz} 
      
          is the same as
      
                  'foo{bar}baz'
      

      and it still goes on a bit. This is the perlop for 5.6.1. Older versions of this document aren't as elaborate, though they still mention that these pairs indeed do nest, at least up to the oldest version I found, v.5.004_05.

      As japhy pointed out some time back the following also work
      s]...]...]; s)...)...); s}...}...};
      It works for al qq constructs. If you're interested peruse Japhys more recent nodes.

      Yves / DeMerphq
      ---
      Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)

        I know, I've already gotten some mileage out of it in a recent obfuscation of mine. Anything that makes the syntax highlighter choke has to be a step in the right direction for that sort of thing.
      Some syntax highlighters also have a distaste for constructs qq}like this}. And find one for me that will work properly after you apply Bleach. :-)
Re: RegExp Delimiter
by Dog and Pony (Priest) on Sep 03, 2002 at 07:08 UTC
    It isn't limited to the regexps, it is all the "Quote and Quote like Operators" - follow the link for at least some details on what is allowed and what is not.
    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.
      Hallelujah!
      For some reason I assumed ?? would work same as //, little realizing that it is its own operator.
      I just couldn't figure out why it only responded to the first instance, until I ran into it through your link...

      10x,
      ---perchance
        // is an m-less form of m//. This means that m?? is the functional equivalent. Or m!!, m>> or even m**.

        Considering // will soon be an operator, things are sure going to get interesting.

        Update:
        What Dog and Pony is talking about is this bit:
        If "/" is the delimiter then the initial m is optional. With the m you can use any pair of non-alphanumeric, non-whitespace characters as delimiters. This is particularly useful for matching path names that contain "/", to avoid LTS (leaning toothpick syndrome). If "?" is the delimiter, then the match-only-once rule of ?PATTERN? applies. If "'" is the delimiter, no interpolation is performed on the PATTERN.
        I find that I use hash-marks as a replacement more often than not(m##), or, on those occasions where that's no good, excamation marks (m!!). Now I remember why I don't use '?'.