atemon has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
The Code
The problem.foreach $FD_NAME ( 1 .. 10) { if( $FD_NAME eq $CATEGORY_DATA{$FD_NAME}{'FIELD_NAME'}) { # Th +e if causing prob #Do my stuff } } print keys %CATEGORY_DATA;
In the "if" if I check for keys 1 & 2 everything is Ok. But when $FD_NAME is 3 ( Or any value which is NOT a key in the hash ) it creates an element in the hash. i.e when I get keys of %CATEGORY_DATA, I am getting all the numbers 1 to 10 :( Is there a way to get only keys which has some values?%CATEGORY_DATA = ( 1 => ( FIELD_NAME => 'id' ), 4 => ( FIELD_NAME => 'name' ), );
Cheers !
--VC
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Automatic creation of hash elements
by kyle (Abbot) on Dec 11, 2007 at 03:56 UTC | |
|
Re: Automatic creation of hash elements
by NetWallah (Canon) on Dec 11, 2007 at 04:46 UTC |