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

Hi, Iam trying to write a source filter using Filter::Simple to use the Binary // (Err) operator in perl6. Iam having a tough time to construct the regex for this. I do have a semi working regex to substitute
$foo = $bar // $baz ; s/(.*\s*)(.*)\b\s*\/\/\s*(.*)\b/$1defined($2) ? $2 : $3/gm;
But I wanted to know if there was a better way of constructing the regex Thanks Ragavendar

Replies are listed 'Best First'.
Re: regex for Err operator.
by dave_the_m (Monsignor) on Aug 23, 2005 at 18:29 UTC
    Are you aware that a patch is available for recent releases of perl 5.8.x to add this feature?

    Dave.

      Hi, I thought it was going to be only released in 5.10 but will take a look at it. But for just the programming satisfaction I wanted to write a source filter. But my knowledge in regex are not upto the mark. At least for the learning aspect I want to get the regex for this. Thanks Raga
Re: regex for Err operator.
by davidrw (Prior) on Aug 23, 2005 at 18:23 UTC
    the actual problem aside, my first thought is to use a different delimiter to make a little more legible (avoid having to escape the slashes):
    s#(.*\s*)(.*)\b\s*//\s*(.*)\b#$1defined($2) ? $2 : $3#gm;
    Second thought is that at least some (if not most) of the * (0 or more) should be + (1 or more). Without them, the regex will match just the string "//".

    also, should "$1defined" be "$1 defined" ?
      Hi, Thanks for your reply. The Err operator is a Binary operator in perl6 and it is //. A binary // operator is the defaulting operator. That is: $a // $b is short for: defined($a) ? $a : $b Because this operator is very useful Iam writing a source filter. Thanks, Raga