in reply to Am I on the pipe, or what?

Perl is seeing the pipe as alternation to nothing, i.e. 'either this or anything else'. Here are the details from a debugging perl (5.8.0-RC1):

$ perl -Dr pipe.pl Omitting $` $& $' support. EXECUTING... Compiling REx `lo/gos' size 4 Got 36 bytes for offset annotations. first at 1 rarest char / at 2 1: EXACT <lo/gos>(4) 4: END(0) anchored `lo/gos' at 0 (checking anchored isall) minlen 6 Offsets: [4] 1[6] 0[0] 0[0] 7[0] Guessing start of match, REx `lo/gos' against `lo/gou'... Did not find anchored substr `lo/gos'... Match rejected by optimizer Freeing REx: `lo/gos' Compiling REx `lo/gou' size 4 Got 36 bytes for offset annotations. first at 1 rarest char / at 2 1: EXACT <lo/gou>(4) 4: END(0) anchored `lo/gou' at 0 (checking anchored isall) minlen 6 Offsets: [4] 1[6] 0[0] 0[0] 7[0] Guessing start of match, REx `lo/gou' against `lo/gou'... Found anchored substr `lo/gou' at offset 0... Guessed: match at offset 0 lo/gou Freeing REx: `lo/gou' Compiling REx `lo/gw|' size 7 Got 60 bytes for offset annotations. 1: BRANCH(5) 2: EXACT <lo/gw>(7) 5: BRANCH(7) 6: NOTHING(7) 7: END(0) minlen 0 Offsets: [7] 0[0] 1[5] 0[0] 0[0] 6[1] 6[0] 7[0] Matching REx `lo/gw|' against `lo/gou' Setting an EVAL scope, savestack=16 0 <> <lo/gou> | 1: BRANCH Setting an EVAL scope, savestack=22 0 <> <lo/gou> | 2: EXACT <lo/gw> failed... 0 <> <lo/gou> | 6: NOTHING 0 <> <lo/gou> | 7: END Match successful! lo/gw| Freeing REx: `lo/gw|' Compiling REx `lo/gon' size 4 Got 36 bytes for offset annotations. first at 1 rarest char / at 2 1: EXACT <lo/gon>(4) 4: END(0) anchored `lo/gon' at 0 (checking anchored isall) minlen 6 Offsets: [4] 1[6] 0[0] 0[0] 7[0] Guessing start of match, REx `lo/gon' against `lo/gou'... Did not find anchored substr `lo/gon'... Match rejected by optimizer Freeing REx: `lo/gon'

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Am I on the pipe, or what?
by flounder99 (Friar) on Jul 10, 2002 at 04:40 UTC
    If you don't want to compile a debugging version use YAPE::Regex::Explain
    use strict; use YAPE::Regex::Explain; print YAPE::Regex::Explain->new(qr'lo/gw|')->explain(); __OUTPUT__ The regular expression: (?-imsx:lo/gw|) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- lo/gw 'lo/gw' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

    --

    flounder