in reply to Whats your favorite nonstandard regex quote char?

Like The Mad Hatter, I favour the pipe.

s|{.*?}|{$sub[$n++]}|g;

It has good visibility, is simple, yaddax3. I toyed around with using #, and it works well as a visual cue, because it registers as 'dark' among visually 'lighter' characters. But accidental obfuscation, as well as inadequate editor syntax hilighting, made me drop that.

I'm not especially fond of ,.`"', because I like for the whole height of the line to be covered. Makes the character look more like a delimiter. Paired delimiters such as []{}()<> do that, but I can't get used to them. They make a lot of sense, and can make certain regexps nice and tidy... but even on multiline things I like my pipe:

s| {.*?} | {$sub[$n++]} |gx;

LAI

__END__

Replies are listed 'Best First'.
Re: Re: Whats your favorite nonstandard regex quote char?
by Enlil (Parson) on Apr 22, 2003 at 17:36 UTC
    Paired delimiters such as []{}()<> do that, but I can't get used to them.

    If it is the pairing you can't get used to, you could always just the right side of the pair. :) e.g.

    $s =~ s>{.*?} >{$sub[$n++]}>gx; $s =~ s){.*?} ){$sub[$n++]})gx;

    Personally I tend to use ! because of the rarity of having to match a ! in a string, or having a negative look-ahead/behind assertions. I do like the way the pipe looks but tend to avoid it because it is the character for alternation.

    -enlil

      Yeah, the half-pair is fun. Personally I would have split up that re as:

      $s =~ s>{.*?} >{$sub[$n++]} >gx;

      ...but TIMTOWTDI. And as for the pipe being the character for alternation... you're right of course. But not many characters are used infrequently enough that they make good delimiters. So I just use whichever I feel looks good until there's a conflict with the content of the regex.

      LAI

      __END__
Re:x2 Whats your favorite nonstandard regex quote char? (paired delimiters)
by grinder (Bishop) on Apr 23, 2003 at 15:38 UTC

    I like using paired delimiters in this context, usually curlies.

    Speaking of quote delimiters, there's a lovely piece of code in Perl_yylex() (in toke.c) to find the matching balanced delimiter of a quoted string:

    if (term && (tmps = strchr("([{< )]}> )]}>",term))) term = tmps[5];

    Pop quiz: why does this work? Why are the closing delimiters repeated twice?

    _____________________________________________
    Come to YAPC::Europe 2003 in Paris, 23-25 July 2003.