iRemix94 has asked for the wisdom of the Perl Monks concerning the following question:
I want to fill a hash with some pairs with a for-loop. I read filenames, split them and push them into the hash. For some reason, the hash gets overwritten with every entry and I can't find the mistake. It's probably a silly mistake, still a PERL - newbee! Here's the code:
opendir(DIR, $semDir); my @filenames =readdir(DIR); closedir(DIR); my %customer_domain_hash; foreach my $line(@filenames) { $line =~ s/\..*//; print "$line\n"; %customer_domain_hash = split(/@@@/, $line); } print Dumper(\%customer_domain_hash)."\n";
This is the result:
CustomerA@@@DomainA CustomerA@@@DomainB CustomerA@@@DomainC CustomerA@@@DomainD CustomerA@@@DomainE CustomerB@@@DomainA CustomerB@@@DomainB CustomerB@@@DomainC CustomerB@@@DomainD CustomerB@@@DomainE $VAR1 = { 'CustomerB' => 'DomainE' };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Filling a Hash
by toolic (Bishop) on Jul 17, 2015 at 13:57 UTC | |
|
Re: Filling a Hash
by hippo (Archbishop) on Jul 17, 2015 at 13:54 UTC | |
by GotToBTru (Prior) on Jul 17, 2015 at 15:52 UTC | |
by Nemo Clericus (Beadle) on Jul 17, 2015 at 14:09 UTC | |
|
Re: Filling a Hash
by stevieb (Canon) on Jul 17, 2015 at 13:45 UTC | |
by iRemix94 (Sexton) on Jul 17, 2015 at 13:51 UTC | |
by stevieb (Canon) on Jul 17, 2015 at 14:09 UTC |