develooper Front page | perl.perl5.porters | Postings from August 2013

Re: [perl #54728] PathTools-3.27 triggers a bug in Perl

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
August 6, 2013 13:31
Subject:
Re: [perl #54728] PathTools-3.27 triggers a bug in Perl
Message ID:
20130806133139.GF2177@iabyn.com
On Tue, Aug 06, 2013 at 04:42:20AM -0700, Victor Efimov via RT wrote:
> On Tue Aug 06 04:24:55 2013, davem wrote:
> > On Mon, Aug 05, 2013 at 08:42:48AM -0700, Victor Efimov via RT wrote:
> > 
> > > Also, isn't this a misfeature?
> > 
> > I don't see why.
> > >
> 
> a) is there a valid case when user indeed wants 'aa' =~ m/(.)/ to modify
> $_[1], in code like this?
> 
> "2" =~ m/(.*)/;
> print test1("1", $1), "\n";
> 
> sub test1 {
>  'aa' =~ m/(.)/;
>  return $_[0].'/'.$_[1];
> }

Probably not, but in the same way that the user probably doesn't want

    sub f { $_ = 1 }

to modify $_[0], but it will if called as

    f($_);

In what ever way that $1 et al are implemented, there will be strange edge
cases where it doesn't do what people expect. If we change it, it will
just swap one set of edge cases for another. By not swapping, we at least
a) don't break code which relies on the current behaviour;
b) mange to do implement it in an efficient way.

> b) I think using regexps with capture groups, before using $_[], or @_,
> or &othersub; without expecting side effects is much more usable than
> this feature.

I think any code that passes raw global 'magic' vars as args to subs (e.g.
without stringifying them a la "$1"), is asking for trouble:

    foo($1, $+[0], $_, $., $!);

-- 
The Enterprise is involved in a bizarre time-warp experience which is in
some way unconnected with the Late 20th Century.
    -- Things That Never Happen in "Star Trek" #14

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