Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A challenge to explain the strange results (under linux)

3 views
Skip to first unread message

Zhu Shanshan

unread,
Jun 11, 2008, 11:59:44 PM6/11/08
to Perl Golf
I used perl "v5.8.5 built for i386-linux-thread-multi".

My data:

##################### File:color.txt

chartreuse

deeppink

goldenrod

lightblue

dodgerblue

darkgoldenrod

My scripts:

##################### File: test.pl

use strict;

use warnings;

open IN,"color.txt" or die;

while (<IN>){

chomp;

print "$_";

}

close IN;

Results under linux platform(Nothing):

"Linux compome 2.6.12-1.1381_FC3smp #1 SMP Fri Oct 21 04:03:26 EDT 2005 i686
i686 i386 GNU/Linux" RedHat

"Linux biome 2.6.9-55.ELsmp #1 SMP Fri Apr 20 16:36:54 EDT 2007 x86_64
x86_64 x86_64 GNU/Linux" RedHat

"Linux hanlab 2.6.16.46-0.12-smp #1 SMP Thu May 17 14:00:09 UTC 2007 i686
i686 i386 GNU/Linux" OpenSUSE

##################### command: perl test.pl

Results under Microsoft Windows XP (in my expectation):

##################### command: d:\soft\bin\perl.exe test.pl

Chartreusedeeppinkgoldenrodlightbluedodgerbluedarkgoldenrod

It's not really a Perl challenge. But can anyone give me some help or
suggestions?

Thanks in advance

Shanshan Zhu

Ronald J Kimball

unread,
Jun 12, 2008, 12:28:20 AM6/12/08
to Zhu Shanshan, Perl Golf
I would bet that your color.txt file has Windows line endings on all
platforms. If you do this:

perl test.pl color.txt | less

you may find that you're getting output after all.


Make sure color.txt has Unix line endings on the Linux machines. Here's
one way to fix it:

perl -pi -e 'tr/\r//d' color.txt

Ronald

Zhu Shanshan

unread,
Jun 12, 2008, 1:29:59 AM6/12/08
to Ronald J Kimball, Perl Golf
Thanks.
As you said, when I substituted "s/\r\n$//" with "chomp", it did work. After
looking up the explanation of "chomp" in perldoc, I found "chomp", which I
always used to remove the newline previous, removes any trailing string that
corresponds to the current value of "$/". And this time, it removed "\n" for
me. I'm really puzzled by this phenomena, because I always work with
"chomp". I guessed the problem came from the new SFTP software used
recently. Then I compared it with WinSCP using the same script. Bingo!
WinSCP has deleted "\r" for me and that's why I could luckily work,
previous.

Anyway, thank you again!


-----邮件原件-----
发件人: Ronald J Kimball [mailto:rjk-pe...@tamias.net]
发送时间: 2008年6月12日 12:28
收件人: Zhu Shanshan
抄送: Perl Golf
主题: Re: A challenge to explain the strange results (under linux)

Daniel Tiefnig

unread,
Jun 12, 2008, 9:15:29 AM6/12/08
to Perl Golf
Zhu Shanshan wrote:
> As you said, when I substituted "s/\r\n$//" with "chomp", it did
> work. After looking up the explanation of "chomp" in perldoc, I found
> "chomp", which I always used to remove the newline previous, removes
> any trailing string that corresponds to the current value of "$/".

Hej,

JFTR, you may also want to have a look at "perldoc perlport". The first
issue discussed is "Newlines".

lg,
daniel

0 new messages