Can only keys be pushed in PERL hash, I mean, Can hash be created without corresponding values?
I want to create a hash which behave just like array i.e. hash with only keys but not corresponding values. Example is given below:
my %feedHash;
while(<CFG>)
{
chomp($_);
my @val=split(/:/,$_);
chomp($val[0]);
my $feedId=$val[0];
if(!exists $feedHash{$feedId})
{
print "\n$feedId Feed is not present";
$hash{$feedId} = undef;
mkdir "LoadReports/$feedId" or die $!;
}
else
{
print '\nFeed is already present';
}
}
It is giving message: "Feed is not present" even for same feed id second time in loop
You can make hash with your keys, where values are set to undef
my %hash;
@hash{qw(key1 key2 key3)} = ();
to check/set for particular hash key,
if (!exists $hash{key4}) { $hash{key4} = undef }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With