in reply to array and hash

Probably an array of arrays is what you want. A-like so:
my @array = get_items(); # whatever. the input. my @results; # each element is a pair: [ input, output ] for my $item ( @array ) { my $output = some_function($item); push @results, [ $item, $output ]; } # now print: for ( @results ) { my( $input, $output ) = @$_; print "Input: $input. Output: $output\n"; }
Something along those lines.

Replies are listed 'Best First'.
Re^2: array and hash
by jdporter (Paladin) on Jun 09, 2005 at 20:44 UTC
    Of course, there are tons of different ways to do something like this.

    You could store the results in a hash rather than array, if inputs are all unique strings:

    my %results; for ( @array ) { $results{$_} = some_func($_); }
    You could make the results array contain hash-based records instead of array-based:
    my @results; for ( @array ) { push @results, { input => $_, output => some_func($_) }; }
    Etc. There's also shortcuts for the loop:
    my %results = map { ( $_ => some_func($_) ) } @array;
    my @results = map { { input => $_, output => some_func($_) } } @array;
    Etc.
Re^2: array and hash
by Anonymous Monk on Jun 09, 2005 at 23:59 UTC
    Hello all, Thank you for all the fast suggestions u gave. I will implement every one of your suggestions.