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

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

Thread Previous | Thread Next
From:
Victor Efimov via RT
Date:
August 7, 2013 10:42
Subject:
[perl #54728] PathTools-3.27 triggers a bug in Perl
Message ID:
rt-3.6.HEAD-2552-1375872165-1704.54728-15-0@perl.org
1) How about notice in perlvar:
"It's not advised to pass directly regular expressions variables to
function as arguments, because function can modify it before use. Use
stringification instead: somefunc("$1")"

before this paragraph:

"Due to an unfortunate accident of Perl's implementation, use English
imposes a considerable performance penalty on all regular expression
matches"

(I am not submitting patch, because almost sure exact wording can be
improved)

2) Would it be useful if I try to improve tests for this (probably
op/local.t, op/magic.t) to test current behaviour and submit a patch?


On Tue Aug 06 06:44:56 2013, vsespb wrote:
> On Tue Aug 06 06:32:12 2013, davem wrote:
> 
> > 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($_);
> 
> if $_ is localized, then code
> 
> sub f { local $_ = 1; print $_[0] }
> $_=2;
> f($_);
> print $_;
> 
> prints 22, so $_[0] is not modified.
> 
> is subroutine intention is to modify global $_, it should be documented,
> and modified $_ and even $_[0] is expected behaviour.
> 
> subroutine that does not localize $_ and does not document this,
> subroutine is buggy imho.
> 
> > 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:
> 
> Ok, get it. So caller responsible for this. Then it's probably thing to
> report as feature request for perlcritic.




---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=54728

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