cyl said:
my script is as below
$i=1;
while(<DATA>){
$x=`dir $_`;
print $i++.". $_";
}
__DATA__
123.txt
456.txt
789.txt
and the output is
1. 123.txt
2.
3. 456.txt
4.
5. 789.txt
Can anyone shed a light on why the extra blank appeared? Thanks.
I have no answers for you, but I will state that unlike the rest of the
responders, I did duplicate your issue. Under Windows 2000
Professional and ActiveState's Perl 5.8.4, the following code (modified
from the above to agree with the Posting Guidelines),
#!/usr/bin/perl
use strict;
use warnings;
my $i = 1;
while (<DATA>) {
chomp;
print "$i: '$_'\n";
$i++;
my $x = qx"dir $_";
}
__DATA__
123.txt
456.txt
789.txt
gave the same output as above. (Except that mine also printed three
"file not founds" because I didn't have those three files).
Very interesting to note is that after I duplicated your problem and
couldn't explain why, I rebooted my computer for an unrelated reason.
I just went back to the same program, without modifying anything, and
now the code works as I expect it to. I get three lines of output,
plus the File Not Founds.
I have no idea what was the original cause of the problem, but the fact
that a reboot solved it leads me to blame Windows in general. I'm
sorry I can't offer more assistance than that.
Paul Lalli