in reply to Re^4: variable inside hash key
in thread variable inside hash key
Works for me. But when in doubt, use the . concat operator, like in the second example below, or in the case of print, the comma operator like in the third example. Otherwise, please be more specific than "it may not work", and provide a piece of example code where it fails (see How do I post a question effectively?).
my $v = { R3R3_1_IF=>"xx", R3R3_2_IF=>"yy", R3R3_3_IF=>"zz" }; my $pic = 1; my $key_MS = sub { "R3R3_${pic}_IF"; }; print "set service-interface $v->{&$key_MS}.0\n"; $pic++; print "set service-interface " . $v->{&$key_MS} . ".0\n"; $pic++; print "set service-interface ", $v->{&$key_MS}, ".0\n"; __END__ set service-interface xx.0 set service-interface yy.0 set service-interface zz.0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: variable inside hash key
by Anonymous Monk on Apr 07, 2016 at 04:54 UTC |