Please help,

I have the following code:

# NAME: lexnum
# Schwartzian Transform algorithm. Returns an array with the sorted keys
in lexical and 
# numeric ascending order.
# ARGUMENTS: hash_reference

sub lexnum {

        my ($hashref) = @_;

        return map { $_->[0] }
                sort { $a->[1] cmp $b->[1] || $a->[2] <=> $b->[2] ||
$a->[3] cmp $b->[3] || $a->[4] <=> $b->[4] }
                map  { [$_,&Transform()] }
                keys %{$hashref};
}

# NAME: Transform
# Part of the Schwartzian Transform algorithm. Splits out the values so
correct sorting on different types
# of key values. Returns the values to the map function
# ARGUMENTS: NO VALUES

sub Transform {

        if ($_ =~ /^(\D+)(\d+)(\D+)(\d+)$/) {
                return ($1,$2,$3,$4);
        }
        if ($_ =~ /^(\D+)(\d+)(.*)$/) {
                &Output("<p>Returning:($1,$2)</p>\n");
                return ($1,$2);
        }
        if ($_ =~ /^(\D+)$/) {
                return ($1);
        }
}

The little &Output function is indeed telling me the if worked fine and
separated the values (an alpha character an a numeric value, like A1,
A2, A3, etc). However when lexnum tries to return something, it returns
nothing:

my ($hashref) = \%::hash;

&Output("<p>Reference to hash: $hashref</p>\n");

my ($sorted) = lexnum ($hashref);

&Output("<p>Returning value:$sorted</p>\n");

The $sorted value comes up with nothing. It should return a reference to
the new sorted hash.

Regards,

Javier Moreno
----------------
Eaton Truck Components
Systems Engineer - Transmissions

"When you have eliminated all which is impossible, then whatever
remains, however improbable, must be the truth" - Sherlock Holmes


_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to