Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't use string as a subroutine

Status
Not open for further replies.

arcnon

Programmer
Aug 12, 2003
242
US
Can't use string ("Menu::quit_now") as a subroutine ref while "strict refs" in use

when I comment out use strict it works fine
how do I get it to work WITH use strict

thanks
 
you can also do this:

[tt]
#!/usr/bin/perl
use strict;
no strict 'refs';
[/tt]

---------------------------------------
If you helped... thx.
 
I figured it out the solution is:

# hash built dynamiclly from a file
%menu_list = (
'3' => 'Menu::new_character',
'4' => 'Menu::quit_now'
);

$input = <STDIN>;
chomp $input;

if ($menu_list{$input}){
$bar = \&{$menu_list{$input}};
}
 
you might want to do this:

eval($menu_list{$input}) if( exists $menu_list{$input});

---------------------------------------
If you helped... thx.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top