$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";
In reply to Re^3: variable inside hash key
by hippo
in thread variable inside hash key
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |