K
Kevin Collins
Hi,
I've just stumbled across a strange problem on my HP-UX systems. The
following code will demonstrate the problem:
#!/usr/bin/perl -w
use strict;
use warnings;
my @list = qw(cc aa bb aa dd zz ee);
print join(" ", sort(UniqArray(@list))) . "\n";
print join(" ", sort(&UniqArray(@list))) . "\n";
sub UniqArray
{
# This function takes an array reference and returns
# an array without dups
# local variables
my %tmp;
my @returns;
foreach (@list)
{
# if the hash element has a value, then don't
# add it to return list since we've already added it
push (@returns, $_) unless ($tmp{$_});
$tmp{$_}++;
}
return @returns;
}
I have two different "home built" versions of Perl (5.6.1 and 5.8.0) and two
HP-supplied versions (5.6.1 and 5.8.0).
The output I would expect:
aa bb cc dd ee zz
aa bb cc dd ee zz
However, here is what I see:
Custom 5.6.1:
ee zz dd aa bb aa cc
aa bb cc dd ee zz
Custom 5.8.0:
ee zz dd aa bb aa cc
aa bb cc dd ee zz
HP's 5.6.1:
ee zz dd aa bb aa cc
aa bb cc dd ee zz
HP's 5.8.0:
aa bb cc dd ee zz
aa bb cc dd ee zz
I also checked Perl 5.8.0 on RedHat 9.0 and see my expected results. I'm
wondering why I need to call &UniqArray(@list) instead of UniqArray(@list)? I
started looking into this when a new script was not giving me a correctly
sorted list. Is there some know issue with this?
Thanks,
Kevin
I've just stumbled across a strange problem on my HP-UX systems. The
following code will demonstrate the problem:
#!/usr/bin/perl -w
use strict;
use warnings;
my @list = qw(cc aa bb aa dd zz ee);
print join(" ", sort(UniqArray(@list))) . "\n";
print join(" ", sort(&UniqArray(@list))) . "\n";
sub UniqArray
{
# This function takes an array reference and returns
# an array without dups
# local variables
my %tmp;
my @returns;
foreach (@list)
{
# if the hash element has a value, then don't
# add it to return list since we've already added it
push (@returns, $_) unless ($tmp{$_});
$tmp{$_}++;
}
return @returns;
}
I have two different "home built" versions of Perl (5.6.1 and 5.8.0) and two
HP-supplied versions (5.6.1 and 5.8.0).
The output I would expect:
aa bb cc dd ee zz
aa bb cc dd ee zz
However, here is what I see:
Custom 5.6.1:
ee zz dd aa bb aa cc
aa bb cc dd ee zz
Custom 5.8.0:
ee zz dd aa bb aa cc
aa bb cc dd ee zz
HP's 5.6.1:
ee zz dd aa bb aa cc
aa bb cc dd ee zz
HP's 5.8.0:
aa bb cc dd ee zz
aa bb cc dd ee zz
I also checked Perl 5.8.0 on RedHat 9.0 and see my expected results. I'm
wondering why I need to call &UniqArray(@list) instead of UniqArray(@list)? I
started looking into this when a new script was not giving me a correctly
sorted list. Is there some know issue with this?
Thanks,
Kevin