develooper Front page | perl.perl5.porters | Postings from March 2003

Re: $_ not optional with lexical prints

Thread Previous | Thread Next
From:
Ronald J Kimball
Date:
March 20, 2003 08:45
Subject:
Re: $_ not optional with lexical prints
Message ID:
20030320164507.GA937066@linguist.thayer.dartmouth.edu
On Thu, Mar 20, 2003 at 05:39:50PM +0100, H.Merijn Brand wrote:

> Why is $_ *not* optional if the file handle is lexical?
> 
> a5:/data/0637/lep 157 > perl5.6.1 -le 'my $v; open $v, ">/dev/null" or die $!; $_ = "Test"; print $v'
> GLOB(0x40013964)
> a5:/data/0637/lep 158 > perl5.8.0 -le 'my $v; open $v, ">/dev/null" or die $!; $_ = "Test"; print $v'
> GLOB(0x4001a364)
> a5:/data/0637/lep 159 > perl5.9.0 -le 'my $v; open $v, ">/dev/null" or die $!; $_ = "Test"; print $v'
> GLOB(0x400197dc)
> a5:/data/0637/lep 160 >
> 
> [ Of course 'print $v $_' goes OK in all examples ]

Well, how is Perl supposed to tell the difference between:

my $v;
open $v, ">/dev/null" or die $!;
$_ = "Test";
print $v;

and

my $v = "Test";
print $v;


Ronald

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