in reply to array matching problems

for ( 0 .. $#numbers ) { push @{$h{$numbers[$_]}}, $strings[$_]; } for ( sort { $a <=> $b } keys %h ) { print join('', @{$h{$_}}), "\n"; }
Boris

Replies are listed 'Best First'.
Re^2: array matching problems
by Anonymous Monk on Jul 29, 2004 at 10:18 UTC
    Hi borisz, mant thanks for you response. The code works well but I don't understand it! How can i get it to print each new string to a new array (where each string can be accessed by element number)? AM
      the first part build a hash of arrays with the numbers as the key.
      %h = ( '1' => [ 'hello', 'you', 'tree' ], '3' => [ 'sun', 'grass' ], '2' => [ 'people', 'fun' ], ... );
      The second for loop grap the array and join the words. To grap a entry use
      $num = 1; $string = join '', @{$h{$num}}; # string is now helloyoutree $num = 4; # select the string with number 4 ( lovefood ) $string = join '', @{$h{$num}};
      Boris