develooper Front page | perl.perl5.porters | Postings from December 2002

Re: difference between my and our before introduction

Thread Previous | Thread Next
From:
hv
Date:
December 22, 2002 20:57
Subject:
Re: difference between my and our before introduction
Message ID:
200212230458.gBN4wbH19045@crypt.compulink.co.uk
Dave Mitchell <davem@fdgroup.com> wrote:
:I'd expect the following to output 12,12; in fact it outputs 12,11
:
:    #!/usr/bin/perl -wl
:
:    $x    = 1;
:    my $x = 2;
:
:    { my  $x = $x+10; print $x }
:    { our $x = $x+10; print $x }
:
:Does anyone else agree that 'our' should behave the same as 'my'
:as regards scope before the variable has been introduced?

I'm not sure that I'd have used those words, but yes I think that
looks like a bug: in C< our $x = $x+10 > the value picked up should
be the $x currently in scope, which in this case would be the
lexical.

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