I run a report between 2 csv files, the last bit i wish to do check is to add matching elemants of the 2 arrays (built up of unique values and occurances) together. but i can't work out how. snippet of code
INPUT output is jon 22 james 12 ken 22 jack 33 jim 11 harry 7 dave 9 grant 12 matt 74 malc 12
INPUT1 output is jon 2 james 1 ken 8 jack 5 jim 1 harry 51 dave 22
output i want is
jon 24 james 13 ken 30 jack 38 jim 12 harry 58 dave 31 grant 12 matt 74 malc 12
code i have so far is
my %seen; seek INPUT, 0, 0; while (<INPUT>) { chomp; my $line = $_; my @elements = split (",", $line); my $col_name = $elements[1]; #print " $col_name \n" if ! $seen{$col_name}++; } while ( my ( $col_name, $times_seen ) = each %seen ) { my $loc_total = $times_seen * $dd; print "\n"; print " $col_name \t\t : = $loc_total"; printf OUTPUT "%-34s = %15s\n", $col_name , " $loc_total "; } ############## ################### my %seen2; seek INPUT1, 0, 0; while (<INPUT1>) { chomp; my $line = $_; my @elements1 = split (",", $line); my $col_name = $elements1[1]; my $col_type = $elements1[5]; $seen2{$col_name}++ if $col_type eq "YES"; } while ( my ( $col_name, $times_seen2 ) = each %seen2 ) { my $loc_total = $times_seen2 ; print "\n $col_name \t\t= $loc_total"; printf OUTPUT "%-34s = %15s\n", $col_name , $times_seen2 ; } close INPUT;

In reply to perl to add results of 2 arrays from 2 files together. by john.tm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.