develooper Front page | perl.perl5.porters | Postings from February 2012

Re: [perl #109542] $1 handled differently in integer arithmetics

Thread Previous | Thread Next
From:
hv
Date:
February 1, 2012 23:07
Subject:
Re: [perl #109542] $1 handled differently in integer arithmetics
Message ID:
201202020653.q126rBu32260@crypt.org
demerphq <demerphq@gmail.com> wrote:
:Maybe we should back up a bit and consider why its ok that $+{match}
:is fine in this context, and $1 isnt, and then figure out if we can
:make $1 work like $+{match}.
:
:Also, i am wondering, we have historically had a lot of trouble due to
:the tied nature of $1 and $2 and the rest of the regex magic vars. I
:am wondering why they have to be magic? Why don't we just copy the
:values and be done with the bugs? If they were true globals, and we
:populated them with localized LVALUES would we not get the same
:effect, and indeed rid ourselves of the bugs and make them updatable
:too?
:
:I mean, we have all the information and infrastructure to do this, is
:there any reason not to?

When would you do it?

I'm pretty sure you must not do it during matching, while still
backtracking, so I guess backreferences within the pattern would still
need to work with the offsets as they do now.

I can't remember right now whether they are made visible to embedded
code; if they are, that becomes rather tricky since you are still
matching at that point. If not, it might be practical to copy at the
point the match is complete, and refer direct to the offsets only
internally for /([ab])\1/ type matches.

I think the big cost will be the multiple copies - I'm sure it is
common to have $_, $& and $1 all refer to the same large string,
and probably not uncommon to have $2 to refer to (say) all but a
few characters of the same.

But in any case I inferred from the rest of the discussion that
pp_multiply is simply doing the wrong thing with magic; if that's
the case $1 is less villain than coughing canary, and the problem
is not best solved by stuffing the canary.

Hugo

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About