in reply to Re^2: variable inside hash key
in thread variable inside hash key
$pic is being incremented. This however has absolutely no effect on $key_MS which was set and evaluated when $pic was still 1. If you want to have it re-evaluated every time it is referenced you would need a closure or an eval or similar. eg. (with the loop replaced for clarity)
#!/usr/bin/env perl use strict; use warnings; my $pic = 1; my $key_MS = sub { "R3R3_${pic}_IF"; }; print "Old pic value is " . &$key_MS . "\n"; $pic = 2; print "New pic value is " . &$key_MS . "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: variable inside hash key
by Anonymous Monk on Apr 06, 2016 at 11:13 UTC | |
by Anonymous Monk on Apr 06, 2016 at 12:23 UTC | |
by Anonymous Monk on Apr 07, 2016 at 04:54 UTC |