in reply to Selecting Correct Array

menu_$foo works if you don't  use strict

my (@menu_info,$foo); $menu_info[1] = "hello"; $foo = "info"; print ${"menu_$foo"}[1];

Replies are listed 'Best First'.
Re: Re: Selecting Correct Array
by RMGir (Prior) on Aug 23, 2002 at 12:42 UTC
    menu_$foo works if you don't use strict
    my (@menu_info,$foo);

    No it won't.

    Symbolic references only work for globals, because lexicals (what "my" makes) don't have symbol table entries, so ${"menu_$foo"} can't find them.

    If you tried your code, you'd see it prints nothing.

    Try this instead:

    our @menu_info; my $foo; $menu_info[1] = "hello"; $foo = "info"; print ${"menu_$foo"}[1];
    But as I mentioned above, don't do this. It only works if you turn off strict 'refs', and then the compiler can't tell you if you're referencing something that's not there, as you did.
    --
    Mike