Hi waytoperl. I think I understand what you are trying to achieve. If not, there should be enough code here for you to modify as needed.

Input CSV

PinName1,Group1 PinName2,Group1 PinName3,AsyncInNoTimingArc PinName4,Group1 PinName5,AsyncInNoTimingArc PinName6,AsyncInNoTimingArc PinName5,AsyncInNoTimingArc

Output RX CSV

$VAR1 = { 'PinName1' => [ 'Group1' ], 'PinName3' => [ 'AsyncInNoTimingArc' ], 'PinName6' => [ 'AsyncInNoTimingArc' ], 'PinName5' => [ 'AsyncInNoTimingArc' ], 'PinName2' => [ 'Group1' ], 'PinName4' => [ 'Group1' ] };

Output CSV

pin(PinName3) { direction : input ; capacitance : 0.0005 ; } internal_power(pwr_arc){ values("0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000 +,0.000000"); related_input : "PinName3" ; pin(PinName5) { direction : input ; capacitance : 0.0005 ; } internal_power(pwr_arc){ values("0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000 +,0.000000"); related_input : "PinName5" ; pin(PinName6) { direction : input ; capacitance : 0.0005 ; } internal_power(pwr_arc){ values("0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000 +,0.000000"); related_input : "PinName6" ; ** Found 3 occurrences of 'AsyncInNoTimingArc' **

Script

#!/usr/bin/perl use strict; use warnings; use diagnostics; use Data::Dumper; die "Error. Usage \'perl csv_parse.pl inputfile.csv outputfile_RX.csv +outputfile.csv\'\n $!" unless $#ARGV == 2; my $infile_CSV = shift @ARGV; my $outfile_RX_CSV = shift @ARGV; my $outfile_CSV = shift @ARGV; sub mainCSV ($$$); # Assign Global Strings my $DIN_CAP = "0.0005"; my $DIN_PWR_ARC = "0.000000,0.000000,0.000000,0.000000,0.000000,0.0000 +00,0.000000,0.000000"; sub mainCSV ($$$) { my $infile_CSV = shift; my $outfile_RX_CSV = shift; my $outfile_CSV = shift; my %hash = (); my $hash_ref = {}; # Read the CSV input file open (my $infile_CSV1, '<', "$infile_CSV") or die "Unable to open +$infile_CSV: $!\n"; while (<$infile_CSV1>) { chomp; ## Skip blank line next if ($_ eq ""); $_ =~ s/\s*\z//; my @array_CSV = split(/,/,$_); my $key_CSV = shift @array_CSV; if (exists $hash{$key_CSV}) { warn "Duplicate key: $key_CSV\n"; } else { $hash{$key_CSV} = \@array_CSV; } } close($infile_CSV1); # Explicit scalar context my $size = scalar keys %hash; # Prints Number of Pins (Hash size...) print "Number of Pins: $size\n"; # Open output CSV in Write Mode. The output file and save hash in +$outfile_RX_CSV open (my $outfile1, '>', "$outfile_RX_CSV") or die "Unable to open + $outfile_CSV: $!\n"; print $outfile1 Dumper(\%hash); close($outfile1); # Open output CSV File in Append Mode open (my $outfile2, '>>', "$outfile_CSV") or die "Unable to open $ +outfile_CSV: $!\n"; print "Stored $size list of pins in $outfile_CSV file.\n"; + # Print key,value where the hash value is AsyncInNoTimingArc my $count_occurrences = 0; foreach my $key (sort keys %hash) { ## Does current hash key value equal AsyncInNoTimingArc if ( @{$hash{$key}}[0] eq "AsyncInNoTimingArc" ) { $count_occurrences++; print $outfile2 "\n", "pin($key) {\n", "direction : input ;\n", "capacitance : $DIN_CAP ;\n", "}\n", "\n", "internal_power(pwr_arc){\n", "values(\"$DIN_PWR_ARC\");\n", "related_input : \"$key\" ;\n"; } } print "\n** Found $count_occurrences occurrences of 'AsyncInNo +TimingArc' **\n"; print $outfile2 "\n\n** Found $count_occurrences occurrences o +f 'AsyncInNoTimingArc' **\n"; close($outfile2); } mainCSV ($infile_CSV,$outfile_RX_CSV,$outfile_CSV);

In reply to Re^3: why i cant print reading hash table? by VincentK
in thread why i cant print reading hash table? by waytoperl

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.