[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Re: Troubles while using m/



Re Gert Kok's message of 1997-10-21, which is included below,
in which an example from perlop.pod doesn't work as described.

I noticed a discrepancy in perlop.pod and have now given this
problem *much* more of my time than it is probably worth,
especially given the results, which are ...

Some vintages of perlop.pod use the example to demonstrate a "c"
modifier, which is described as altering the function of the "g"
modifier such that pos is *not* reset when a match fails. The use is
shown as:

                m/.../gc

Other versions, such as the one currently at
    http://www.perl.com/CPAN-local/doc/manual/html/pod/perlop.html
never even mention this "c" modifier, yet they contain the example
that doesn't work, in which all of the m/.../gc expressions have been
changed to m/.../g

I tried running the example on two versions of PC Perl, a Unix Perl,
and MacPerl.

    - Without the "c" modifier, pos always has a null value
    - With the "c" modifier:
        Some versions provide the output described in perlop.pod
        Other versions dislike the "c" modifier and complain:
            "Bare word found where operator expected, near ..."

Apparently the "c" modifier feature has been deleted ... or has it
been added ???

    I thought I had this figured out, but as I put version numbers
    for perlop.pod and the Perl implementations into the above I
    realized that they were contradictory and only added to my
    confusion: some that are later versions than others implement
    and/or document the "c" modifier, and some seem to be the other
    way around.

It *is* clear that this example in the perlop.pod document is
sometimes not in-sync with the implementation that accompanies it.

Matthias pointed out in his message of 1997-10-21:

> You're looping *until* the match fails, and after a failed match,
> pos will return nothing.

This is the behavior that the "c" option is described as suppressing
and was, I think, the whole point of the example program. I can't
tell which is "old" and which is "new", but in either case, if
the implementation performs as described by Matthias and also does
not implement the "c" modifier, then the example in perlop.pod is
meaningless for that implementation and should be (should have
been??) completely deleted from that implementation's documentation.
Instead, some versions simply delete the "c" modifier from the
perlop.pod example and then the example doesn't work.  At least, that
is what my experiments show.

To answer Gert Kok's questions:

> So it seems that pos is unknown to MacPerl?

    It is known and it works in MacPerl.  But the example doesn't
    work unless the "c" modifier is used, and this modifier is not
    accepted by some implementations.

> Am I perhaps reading documentation that is not valid for
> this version of MacPerl?

    I think so.

Maybe someone with a more complete history of perl versions and
documents can determine if the "c" modifier is a new feature that has
just been added, an old feature that has just gone away, or a
proposed feature that was implemented sporadically. It would also be
worthwhile to assure that the latest perlop.pod and implementation
agree with each other.

    -Paul-       paul.b.patton@hbc.honeywell.com

==================================================

>From: G_L_H_Kok@fbw.vu.nl
>To:  mac-perl@iis.ee.ethz.ch
>Subject:  [MacPerl] Troubles while using m/
>
>Date: 1997-10-21 16:12
>Priority: 3
>
>-----------------------------------------------------------------------------
-
>
>(Using MacPerl 5.1.4r4 on 68K Mac)
>
>On the way of learning Perl,
>I wanted to know more about regexp's in combination with /g, and
>tried the following example from an 5.004 perlop page;
>
># using m//g with \G
>$_ = "ppooqppq";
>while ($i++ < 2) {
>    print "1: '";
>    print $1 while /(o)/g; print "', pos=", pos, "\n";
>    print "2: '";
>    print $1 if /\G(q)/;   print "', pos=", pos, "\n";
>    print "3: '";
>    print $1 while /(p)/g; print "', pos=", pos, "\n";
>}
>
>The example should print:
>
>
>1: 'oo', pos=4
>2: 'q', pos=4
>3: 'pp', pos=7
>1: '', pos=7
>2: 'q', pos=7
>3: '', pos=7
>
>But it prints:
>
>1: 'oo', pos=
>2: '', pos=
>3: 'pppp', pos=
>1: 'oo', pos=
>2: '', pos=
>3: 'pppp', pos=
>
>So it seems that pos is unknown to MacPerl?
>
>The perlop/perlre pages also states that \G and //g can be
>used one or the other; which differs from the doc for MacPerl
>that both should be used together.
>
>Am I doing something wrong?
>Am I perhaps reading documentation that is not valid for
>this version of MacPerl?
>
>Gert Kok
>Faculty of Human Movement Sciences
>Vrije Universiteit Amsterdam
>The Netherlands

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch