PDA

View Full Version : Differences between Perl on Win2k and Linux?


stoney79
January 13th, 2005, 02:18 PM
Hi guys,

I'm new here so apologies if I've picked the wrong forum. The Programming forum pointed me here, since I've a question about Perl so I hope this is the right spot ;)

Ok... I've received a Perl script that works fine on Win2k running under ActiveState Perl 5.6.1 that I want to run under Linux (again, ActiveState Perl 5.6.1). Except, the script falls over. Here's the chunk of code:

open (PRJLISTFILE,"<$ENV{'_TMROOT'}/project/prjlist.txt")
LOOP: while (defined($PrjListLine=<PRJLISTFILE>)){
chomp $PrjListLine;
next LOOP if ($PrjListLine =~ /^\#/);
next LOOP if ($PrjListLine =~ /^\s*$/);
$PrjListLine =~ s/\#.*//g;
$RootLocations = $RootLocations." ".$PrjListLine;
}
#print STDOUT $RootLocations;
close PRJLISTFILE;

When running on the Windows PC it works fine, with $RootLocations looking something like this:

$ROOT/peripherals $ROOT/audio $ROOT/graphics

while on Linux, all the values are munged to something like this:

$ROOT/graphicsals

So, graphics has overwritten peripherals. Any idea what would be causing this? I've drawn a complete blank other than a bug in Perl. I've also tried it with ActiveState Perl 5.8.1 as well with the same results.

Any help would be really appreciated so thanks in advance guys (and/or girls)!

Tony

z1p
January 13th, 2005, 03:01 PM
stoney, I'm not seeing anything wrong, but you could try alternative ways of doing the same thing.

#1 $TmpLocation = $RootLocations." ".$PrjListLine; $RootLocations = TmpLocation;
#2 $RootLocations = "$RootLocations $PrjListLine";
#3 $RootLocations = $RootLocations . " " . $PrjListLine; #the spaces may help???

#4 #Use an array and add to it in the loop
push @RootArray, $PrjListLine;

#After the end of the loop
$RootLocations = join " ",@RootArray;

degsy
January 13th, 2005, 03:06 PM
I don't know much about perl but could it be that you are missing some formatting code.
Windows may take whitespace as a space, but linux may need the code use as non-breaking space character or newline \n

stoney79
January 13th, 2005, 03:27 PM
Thanks guys - I asked a friend and it was the CRLF problem after all. Chomp only removed the LF, not the CR and so was sending the next character to the beginning of the variable - hence the overwriting.

Thanks so much for your time and quick answers though! :thumbsup: