Hi all,

After I succeeded in combining the two files into one using hash, I have a problem now to add one more column into the last column. So I have these two files:

File1: Item,Period,Waveform,Attributes,Sources an_en11,200.00,{0 133},{ } br_gh13,140.09,{0 59},{ } ce_oy74,300.05,{0 230},{int_43} dt_pp50,200.11,{0 122},{ } er_tk02,305.47,{0 220},{ } ef_yb41,200.05,{0 233},{ } File2: Item,Sink,Buffer,Cell,Slew,Path,Violation,Area dt_pp50,0,0,2,0.000,0.000,0,0.000 er_tk02,0,2,3,0.002,0.004,0,0.001 ef_yb41,0,1,5,0.000,0.000,0,0.000

I wish to generate the last column (%Skew) by using (Slew/Period)*100%.

Item,Sink,Buffer,Cell,Slew,Path,Violation,Area,Period,%Skew dt_pp50,0,0,2,0.000,0.000,0,0.000,200.11,(Slew/Period)x100% er_tk02,0,2,3,0.002,0.004,0,0.001,305.47,(Slew/Period)x100% ef_yb41,0,1,5,0.000,0.000,0,0.000,200.05,(Slew/Period)x100%

Is there any suggestion on what command should i use in my script to get the output? My code :

#! /usr/intel/bin/perl-w use strict; use warnings; my %file1Hash; my $value1; open my $file1, "<","design.rpt.csv"; open my $file2, "<","summary.rpt.csv"; open my $outfile_1, ">", "combined.rpt.csv"; print $output_1 "Item, Sink, Bufer, Cells, Slew, Path, Violation, Area +, Period, %Skew\n"; while(my $line = <$file1>){ chomp $line; my($key, $value1) = (split /,/, $line); if (defined $key) { $file1Hash{$key}= $value1; } else { # print $line."\n"; } } while(my $line1 = <$file2>){ chomp $line1; my($key1) = (split /,/, $line1) ; if (defined $file1Hash{$key1}) { print $outfile_1 $line1.",".$file1Hash{$key1}."\n"; + } else { # print $line1."\n"; } } close $file1; close $file2; close $outfile_1;

Where should i start or how do i start?


In reply to How to add a new column into my csv file? by chaney123

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.