Perl on WinXP: transliteration produces different results on differentmachines

Perl on WinXP: transliteration produces different results on differentmachines

am 08.10.2007 20:43:46 von HH

I use the ActiveState Perl installation 5.8.8 (build 822) on two
different Windows XP machines. The following simple code

$string = "ABCxyz";
print "$string\n";
$string = ~ tr/A-Z/a-z/;
print "$string\n";

produces different results on the two machines. On machine 1, I obtain

ABCxyz
abcxyz

as it should be, and on machine 2, I get

ABCxyz
4294967295

Any idea what's going? --- I presume it'll be something rather trivial
since I am a Perl novice, but searching around everywhere I haven't been
able to find anything.

Thanks.
--hh

Re: Perl on WinXP: transliteration produces different results ondifferent machines

am 08.10.2007 21:42:58 von HH

On 10/8/2007 2:43 PM, hh wrote:
> I use the ActiveState Perl installation 5.8.8 (build 822) on two
> different Windows XP machines. The following simple code
>
> $string = "ABCxyz";
> print "$string\n";
> $string = ~ tr/A-Z/a-z/;
> print "$string\n";
>
> produces different results on the two machines. On machine 1, I obtain
>
> ABCxyz
> abcxyz
>
> as it should be, and on machine 2, I get
>
> ABCxyz
> 4294967295
>
> Any idea what's going? --- I presume it'll be something rather trivial
> since I am a Perl novice, but searching around everywhere I haven't been
> able to find anything.
>
> Thanks.
> --hh

Never mind, I found the error. Somehow I had erroneously inserted a
blank space into the binding operator (=~) in the code for machine 2
(reproduced above) which was not present in the code for machine 1.

I knew it was a trivial error.
Sorry!

Re: Perl on WinXP: transliteration produces different results on differentmachines

am 08.10.2007 21:53:25 von Ben Morrow

Quoth hh :
> I use the ActiveState Perl installation 5.8.8 (build 822) on two
> different Windows XP machines. The following simple code
>
> $string = "ABCxyz";
> print "$string\n";
> $string = ~ tr/A-Z/a-z/;
> print "$string\n";
>
> produces different results on the two machines. On machine 1, I obtain
>
> ABCxyz
> abcxyz
>
> as it should be, and on machine 2, I get
>
> ABCxyz
> 4294967295
>
> Any idea what's going? --- I presume it'll be something rather trivial
> since I am a Perl novice, but searching around everywhere I haven't been
> able to find anything.

The =~ operator must be written with no whitespace. What you have above
parses as

$string = (~ tr/A-Z/a-z);

that is, it performs tr/// on $_, which returns a count of translations,
and then assigns the bitwise-not of that value to $string. I don't
really understand why it 'works' on one of your machines, unless the
script is not in fact the same in both cases.

The -p option to B::Deparse can be helpful in these cases:

~% perl -MO=Deparse,-p -e'$x = ~ tr/A-Z/a-z/'
($x = (~tr/A-Z/a-z/));
-e syntax OK

(translate as appropriate for cmd.exe, of course...).

FYI, if you set $\ you don't need to explicitly print the "\n" at the
ends of you lines...

Ben

Re: Perl on WinXP: transliteration produces different results ondifferent machines

am 08.10.2007 21:58:47 von Martijn Lievaart

On Mon, 08 Oct 2007 14:43:46 -0400, hh wrote:

> I use the ActiveState Perl installation 5.8.8 (build 822) on two
> different Windows XP machines. The following simple code
>
> $string = "ABCxyz";
> print "$string\n";
> $string = ~ tr/A-Z/a-z/;
> print "$string\n";
>
> produces different results on the two machines. On machine 1, I obtain
>
> ABCxyz
> abcxyz
>
> as it should be, and on machine 2, I get
>
> ABCxyz
> 4294967295
>
> Any idea what's going? --- I presume it'll be something rather trivial
> since I am a Perl novice, but searching around everywhere I haven't been
> able to find anything.

[martijn@cow ~]$ perl -e '$string = "ABCxyz";
print "$string\n";
$string = ~ tr/A-Z/a-z/;
print "$string\n";'
ABCxyz
18446744073709551615
[martijn@cow ~]$ perl -e '$string = "ABCxyz";
print "$string\n";
$string =~ tr/A-Z/a-z/;
print "$string\n";'
ABCxyz
abcxyz
[martijn@cow ~]$

Notice the difference between the two programs!

M4

Re: Perl on WinXP: transliteration produces different results ondifferent machines

am 08.10.2007 23:46:28 von Dummy

hh wrote:
> I use the ActiveState Perl installation 5.8.8 (build 822) on two
> different Windows XP machines. The following simple code
>
> $string = "ABCxyz";
> print "$string\n";
> $string = ~ tr/A-Z/a-z/;
> print "$string\n";
>
> produces different results on the two machines. On machine 1, I obtain
>
> ABCxyz
> abcxyz
>
> as it should be, and on machine 2, I get
>
> ABCxyz
> 4294967295
>
> Any idea what's going? --- I presume it'll be something rather trivial
> since I am a Perl novice, but searching around everywhere I haven't been
> able to find anything.

Why not just use:

$string = lc $string;

on both machines?



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Re: Perl on WinXP: transliteration produces different results on different machines

am 09.10.2007 00:48:43 von Tad McClellan

hh wrote:
> On 10/8/2007 2:43 PM, hh wrote:


>> $string = ~ tr/A-Z/a-z/;

>> I get
>>
>> ABCxyz
>> 4294967295


> Never mind, I found the error.


If you had enabled warnings, then perl would have found it *for you*.

You should always enable warnings when developing Perl code.


> Somehow I had erroneously inserted a
> blank space into the binding operator (=~) in the code for machine 2
> (reproduced above) which was not present in the code for machine 1.
>
> I knew it was a trivial error.


Your trivial error was not enabling warnings...


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"