CropCircle has asked for the wisdom of the Perl Monks concerning the following question:
Hello! Is it possible to fill a hash in loop? Here is a code:
my @var_array = (1,2,3,4,5,6); my $var, my $r = 0; my %hash(); foreach my $var_p (@var_array){ $var = 3+$r; #hash with $var_p key and $var value: #%hash = ( # 1 => 3, # 2 => 4, # ... # 6 => 8, #); print "### $var\n"; $r++; }
Thank you for help!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Filling a hash in loop
by Corion (Patriarch) on Apr 13, 2015 at 08:13 UTC | |
|
Re: Filling a hash in loop
by QM (Parson) on Apr 13, 2015 at 08:22 UTC | |
|
Re: Filling a hash in loop
by Anonymous Monk on Apr 13, 2015 at 09:01 UTC | |
|
Re: Filling a hash in loop
by AnomalousMonk (Archbishop) on Apr 13, 2015 at 15:39 UTC | |
|
Re: Filling a hash in loop
by jeffa (Bishop) on Apr 13, 2015 at 17:01 UTC |