Bug?: backticks operator upsetting while(<FH>)

B

Bob Walton

In this program:

#!/usr/local/bin/perl --
use strict;
use warnings;
while(<DATA>){
chomp;
print "read >>$_<<\n";
`rem`; #for Win32 -- just a do-nothing command
}
__END__
Line one
Line two
Line three

I note the output is:

D:\junk>perl junk473.pl
read >>Line one<<
read >><<
read >>Line two<<
read >><<
read >>Line three<<

D:\junk>

An extra pass through the while loop is being taken when the ``'s are
present. If the `rem`; line is commented, the output is as expected:

D:\junk>perl junk473.pl
read >>Line one<<
read >>Line two<<
read >>Line three<<

D:\junk>

Replacing the `rem`; line with system('rem'); results in the same
behavior. The command passed doesn't matter -- valid or invalid.
Without the chomp; line, $_ consists of a newline on the extra passes
through the while loop.

D:\junk>perl -v

This is perl, v5.8.4 built for MSWin32-x86-multi-thread
(with 3 registered patches, see perl -V for more detail)

Copyright 1987-2004, Larry Wall

Binary build 810 provided by ActiveState Corp. http://www.ActiveState.com
ActiveState is a division of Sophos.
Built Jun 1 2004 11:52:21

D:\junk>ver

Windows 98 [Version 4.10.2222]


Does this plague Perl versions other than 5.8.4, or other Windows
versions or other OS's? Thanks.
 
B

Brian McCauley

Bob Walton said:
Does this plague Perl versions other than 5.8.4, or other Windows
versions or other OS's? Thanks.

I can reproduce it in 5.8.0 on windows.

I cannot reproduce it on 5.6.1 on windows or Linux.

I cannot reproduce it on 5.8.0 on Linux.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top