menylea has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks: IM creating a hash using (inside a foreach loop):
$symbol_list_hash{$1}= [split(' ',substr $2, 0, (index($2, ")")))]
it yield somting that looks like that :
$VAR1 = { 'I2' => [ 'VSS', 'VSS', 'Rep_en', 'ENb', 'VDD', 'VDD' ], 'I9' => [ 'Vctrl', 'ENq', 'net014', 'Vb_CS_LNA', 'VDD_OpAmp', 'VSS' ], 'I3' => [ 'VSS', 'VSS', 'ENb', 'ENq', 'VDD', 'VDD' ] };
than, Im trying to search/grep for a spacific value for all of the keys ( I3, I9,I2 ), using :
..if (!grep{ $dd eq "$_"} values %symbol_list_hash )
but it never find if, and sometimes it gives an error :
"cant coerance into array...."
the thing is, as far as I can understand the array should look like that :
$VAR1 = { 'I2' => [ 'VSS' => 'VSS', 'VSS'=> VSS, 'Rep_en'=>'Rep_en' ,
How do I converte it? thx meny both solutions doest work: it gives:
cant coerce into hash at.... attemp to free unreferanced scalar..

Replies are listed 'Best First'.
Re: manipulation to hash
by toolic (Bishop) on Jun 12, 2012 at 15:06 UTC
    I believe you have a hash-of-arrays. If you want to get at the individual array elements, you need to dereference the arrays:
    use warnings; use strict; my %symbol_list_hash = ( 'I2' => [ 'VSS', 'VSS', 'Rep_en', 'ENb', 'VDD', 'VDD' ], 'I9' => [ 'Vctrl', 'ENq', 'net014', 'Vb_CS_LNA', 'VDD_OpAmp', 'VSS' ], 'I3' => [ 'VSS', 'VSS', 'ENb', 'ENq', 'VDD', 'VDD' ] ); for my $aref (values %symbol_list_hash) { my @arr = @{ $aref }; print "$_\n" for @arr; # do someting with each element }

    See also:

Re: manipulation to hash
by NetWallah (Canon) on Jun 13, 2012 at 00:09 UTC
    Try this:
    if ( !grep{ $dd eq $_} map{values %$_} values %symbol_list_hash )

                 I hope life isn't a big joke, because I don't get it.
                       -SNL