develooper Front page | perl.perl5.porters | Postings from May 2008

Re: [perl #53504] Bug in if(open(my $fh,...)) { } scoping

Thread Previous | Thread Next
From:
Marc Lehmann
Date:
May 2, 2008 10:01
Subject:
Re: [perl #53504] Bug in if(open(my $fh,...)) { } scoping
Message ID:
20080502170104.GB22218@schmorp.de
On Wed, Apr 30, 2008 at 10:14:15AM -0400, Matt Sergeant <matt@sergeant.org> wrote:
> >if ((my $ret = somecall()) == 0) {
> >    # profit !
> 
> I know. I just don't think it's used like that very much (if at  
> all?), and I don't think the chosen implementation makes visual sense.

For what it's worth, C++ has the same scoping rule (else scope included,
and I use it a lot in C++, but little in Perl, for some reason I cannot
quite explain).

So at least c++ and perl programmers have one difference less to remember
(not that it matters).

On Thu, May 01, 2008 at 12:14:55PM +0200, Aristotle Pagaltzis <pagaltzis@gmx.de> wrote:
> * Matt Sergeant <matt@sergeant.org> [2008-04-30 16:15]:
> > If we'd have had given/when back then I suspect the scoping
> > would have been implemented differently.
> 
> Well yeah – one of the many things Perl 6 canonicalises is that
> there are no edge cases in scoping. A variable declared within a
> pair of curlies is local to it, and a variable declared outside
> is not, and no constructs leak scopes across blocks somehow.

So the my variable would not be local to the if at all in this case, but
to the outer block? Thats quite horrible, IMnsHO (even C++ managed to
correct this mistake in scoping :) But then, perl6 r.i.p. :=)

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      pcg@goof.com
      -=====/_/_//_/\_,_/ /_/\_\

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