Okay, so I'm trying to implement your radix sort, and something's going wrong.
When I turn on warnings (I'm using Perl v5.6.0) I get:
Multidimensional syntax $table[substr $_, $i, 1] not supported at ./sort3.pl line 31.
and when I turn on strict:
Can't use an undefined value as an ARRAY reference at ./sort3.pl line 30.

The program runs okay when I use a regular sort, but when I switch
the comment lines to try to run the radix, then I get those warnings and strict errors.
Turning off warnings and strict results in the original list unchanged.
Is this a situation where I need a newer version of Perl, or am I
doing something wrong?

my $max=10;
my $size=10;
my @result;
my @array=Generate();
#@result=(sort radix_sort @array);
@result=(sort @array);                     # Move commenting line up to run radix

for (my $i=0; $i<=$#array; $i++) {
    print "$array[$i] $result[$i]\n";
}

sub Generate {
    my @array;
    for (my $i=0; $i<$max; $i++) {
        for (my $j=0; $j<$size; $j++) {
            my $char=(chr(rand(26)+97));
            $array[$i].=$char;
        }
    }
    return (@array);
}

sub radix_sort {
  my $a = shift;

  for my $i (reverse(0 .. @$a-1)) {
    my @table;
    for (@$a) {
      push @{ $table[substr $_, $i, 1] }, $_;
    }
    @$a = map @$_, @table;
  }
}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to