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

Re: $_ not optional with lexical prints

Thread Previous | Thread Next
From:
H.Merijn Brand
Date:
March 20, 2003 08:47
Subject:
Re: $_ not optional with lexical prints
Message ID:
20030320174631.DFD2.H.M.BRAND@hccnet.nl
On Thu 20 Mar 2003 17:45, Ronald J Kimball <rjk@linguist.Thayer.dartmouth.edu> wrote:
> 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;

It does know that $v is bound to an I/O channel.

-- 
H.Merijn Brand        Amsterdam Perl Mongers (http://amsterdam.pm.org/)
using perl-5.6.1, 5.8.0 & 633 on HP-UX 10.20 & 11.00, AIX 4.2, AIX 4.3,
  WinNT 4, Win2K pro & WinCE 2.11.  Smoking perl CORE: smokers@perl.org
http://archives.develooper.com/daily-build@perl.org/   perl-qa@perl.org
send smoke reports to: smokers-reports@perl.org, QA: http://qa.perl.org



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