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

$_ not optional with lexical prints

Thread Next
From:
H.Merijn Brand
Date:
March 20, 2003 08:39
Subject:
$_ not optional with lexical prints
Message ID:
20030320173349.DFCF.H.M.BRAND@hccnet.nl
Before I state that it is a bug - which it probably is not - I'd like
to say that at least it does not DWIM to me

$_ = "Blah\n";
print;

will print "Blah\n" to the current selected filehandle (default STDOUT)
$_ is optional.

open FIL, ">BLAH" or die "BLAH: $!";
print FIL;

will most likely print "Blah\n" to the just created file BLAH.
Again, the $_ is optional

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 ]

-- 
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 Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About