Why does the following program print "Undefined! "? Shouldn't the subroutine
leave the value of $x alone? (I can understand it clobbering $_, but $x?)
#!/usr/bin/perl -w
use strict;
sub readZip() {
open FH, '/dev/null';
while (<FH>) { print "Got something!\n"; }
}
my $x = 'hi';
for ($x) { readZip(); }
print "Undefined! \n" unless defined $x;
(I'm using perl 5.6.1)
Thanks,
Ted Hopp
ted@newslate.co m
leave the value of $x alone? (I can understand it clobbering $_, but $x?)
#!/usr/bin/perl -w
use strict;
sub readZip() {
open FH, '/dev/null';
while (<FH>) { print "Got something!\n"; }
}
my $x = 'hi';
for ($x) { readZip(); }
print "Undefined! \n" unless defined $x;
(I'm using perl 5.6.1)
Thanks,
Ted Hopp
ted@newslate.co m
Comment