#!/usr/bin/perl
use warnings;
use strict;
#Hello all, I have a school assignment but I seem to be unable to begi
+n... What I was given is something like the following
my @out= split ',', "b,a,c,d,a,b,f,g,a,c,g"; # look no warning
my @out1=(1,2,3,1,2,3,4,5,2,3,2);#the numbers declares how many times
++the letters from the @out are found
#I want to make a hash contains as keys the unique elements from the @
+out and as values the sums of the letters from the @out1. Also I want
+ the hash to be sorted
#This is the preview of the hash
my %hash=(a=>6,b=>4,c=>6,d=>1,f=>4,g=>7);
#any ideas please?
### Remember to use warnings and strict (put it on the first lines of
+your code):
# ok
### You can iterate the keys of the hash in order as follows:
print "preview:\n";
print "$_: \t$hash{$_}\n" for sort keys %hash;
# ok, let me try a simpler problem first
my %counts;
for (@out) {
$counts{$_}++;
}
print "simpler:\n";
print "$_: \t$counts{$_}\n" for sort keys %counts;
# that worked, let me try the full assignment
my %counts2;
for (@out) {
my $count = shift @out1;
$counts2{$_} += $count;
}
print "full:\n";
print "$_: \t$counts2{$_}\n" for sort keys %counts2;
# this looks about right.