On Jun 24 2001, Michael Fowler wrote:
> On Sun, Jun 24, 2001 at 07:13:47PM -0300, Rogério Brito wrote:
> > 1 - How does the Perl grammar interprets the following statements:
> >
> > $n = () = m/string/g;
> >
> > In particular, is "()" an lvalue in Perl?
>
> Yes, it is. () is a list assignment with no values.
First of all, I'd like to thank Michael and Japhy for their
responses to my questions. Thank you very much.
I'm now a little bit confused. You meant "() is IN a list
assignment...", right (since it would provide the list context
to the assignment, =, operator)? Or did you mean that () IS
indeed an assignment?
I'm a bit lost here, since I would have thought that () would
be a literal/constant empty list, like, say "" is the empty
literal string in C.
To make matters worse, I thought that since (1, 2, 3) is a
literal, non-empty list, that () would be the similar,
constant empty string. It was my surprise that the snippet
above indeed worked -- I guess I'm not enough familiar with
the semantics of the language. :-(
But if () is an lvalue in perl, where are its contents stored?
Is it similar to a lambda function in LISP/Scheme?
Perhaps my experience with other languages is distracting me
here. :-(
> > 2 - Why does the following snippet prints 3 and not 4?
(...)
> > Perl seems to not be finding occurences of overlapped
> > patterns (as I would expect from the implementation of a
> > Boyer-Moore algorithm -- which I read somewhere that Perl
> > uses when dealing with simple patterns).
>
> This behaviour of m//g, not matching overlaps, is desirable and correct.
It may be desired, but I'm not so sure that it is "correct".
I'm not even sure that there is only one value of correct,
since I can count at least two such values. :-)
> m//g is usually used for parsing, not counting occurrences, and parsing out
> overlaps as individual tokens would be a Very Bad Thing.
Well, the perlop manpage should be changed then. :-(
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
g Match globally, i.e., find all occurrences.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The problem is that my edition of "Programming Perl" (2nd)
also has this exact same phrase on page 69.
I guess that it should be clarified, since the more
strict/mathematical/theoretical minds of the audience would
think that "all occurrences" would catch everything. :-)
[]s, Roger...
P.S.: On page 71, it says "The /g modifier specifies global pattern
matching---that is, matching as many times as possible within a
string". Perhaps both semantics could be provided by Perl in a future
version? If not possible, giving a warning would be fine.
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Rogério Brito - [EMAIL PROTECTED] - http://www.ime.usp.br/~rbrito/
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=