Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Print Hash Keys to a file for corresponding Hash values

by ig (Vicar)
on Nov 20, 2013 at 20:28 UTC ( #1063600=note: print w/replies, xml ) Need Help??


in reply to Print Hash Keys to a file for corresponding Hash values

I don't understand your description of your problem or what you want to achieve, so I am guessing here...

I guess you are having difficulty with the output to $outfile at the end of sub mainCSV and that you want "pin" and "related_input : " to be followed by the key and corresponding values from your hash.

If my guess is correct, there are a couple of problems:

The values of %hash are references to arrays, so I don't think the grep just after "Continue print with corresponding hash key and value for AsyncIn" does what you want.

Then, iterating a loop for the number of times there is a particular value in the hash doesn't make it easy to access the keys or values of the hash.

So, you need a different approach, and it is not clear from what you have presented exactly what you are trying to achieve.

Here is something for you to consider but, again, it is only a guess as to what you want and it is untested:

# Continue print with corresponding hash key and value for AsyncIn +NoTimingArc # Find the keys for which AsyncInNoTimingArc is in the value array my @keys = grep { my @array_CSV = @{$hash{$_}}; grep { $_ eq 'AsyncInNoTimingArc'} @array_CSV; } keys %hash; open (my $outfile1, '>>', "$outfile") or die "Unable to open $outf +ile: $!\n"; foreach my $key (@keys) { # Get the values corresponding to this key my $values = join(', ', @{$hash{$key}}); print <<" EOF"; pin(\"$key => {$values}\") { direction : input ; capacitance : $DIN_CAP ; } internal_power(pwr_arc){ values(\"$DIN_PWR_ARC\"); related_input : \"$key => {$values}\" ; } EOF }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1063600]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2020-09-20 09:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (120 votes). Check out past polls.

    Notices?