[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re-2: [MacPerl] using one array to sort another




Alan,

Here's what you actually asked for... if you're willing to use a hash -
which would presumably be convenient for whatever other processing you're
doing.  (The anonymous hash is nice because you can pass it to subs with
minimal overhead).

rkm

    -------------------------------------------------
    #!/usr/bin/perl -w
    use diagnostics ;
    use strict ;

    my @compArray =
        ( '1' , '1.1' , '1.1.p.1' , '1.1.1' , '1.1.2' , '1.1.3' ) ;

    my $names =
    {
        '1.1.2' => 'Jeff||Alexander',
        '1' => 'Joe||Alexander',
        '1.1.p.1' => 'Claudia||Alexander',
        '1.1' => 'Nathan||Alexander',
        '1.1.3' => 'Herb||Alexander',
        '1.1.1' => 'Bob||Alexander'
    } ;


    my @results = map $_ . '|||' . $names->{$_} . "\n" , @compArray ;

    print @results ;


    ## Prints:
    ##
    ## 1|||Joe||Alexander
    ## 1.1|||Nathan||Alexander
    ## 1.1.p.1|||Claudia||Alexander
    ## 1.1.1|||Bob||Alexander
    ## 1.1.2|||Jeff||Alexander
    ## 1.1.3|||Herb||Alexander
    -------------------------------------------------

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org