in reply to Regarding arrays
array1 = %w( ME K LE K HT ME LL ) array2 = [ 10, 4, 1, 5, 6, 7, 19 ] sums = Hash.new( 0 ) array1.zip( array2 ).each { |(k,v)| sums[k] += v } array1.each { |k| puts "#{k}=#{sums[k]}" }
Update: The Ruby's because of the homework stench. This translates all but verbatim into Perl (presuming you know that pairwise { [ $a, $b ] } @Array1, @Array2; is the List::MoreUtils equivalent of Ruby's Array#zip). Just add sigils and shake!
|
---|