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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hash of subroutines.. not quite working 1

Status
Not open for further replies.

travs69

MIS
Dec 21, 2006
1,431
US
I'm 99% sure you can do this but I can't get it. Any help is appreciated
Code:
my %equipment_sub_map = {
'CISCO 2651 ROUTER' => \&cisco_2651,
'CISCO 3845-V/K9 VOICE BUNDLE ROUTER' => sub{print "Hi\n";},
};

sub cisco_2651 {
	print "Hi 2\n";
}


&{$equipment_sub_map{"CISCO 2651 ROUTER"}};


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
hahahaha :)

duh


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Is there a reason to leave the \& in front of the cisco_2651? It seems to work without it.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Yes it does, and you can also write [tt]$equipment_sub_map{'CISCO 2651 ROUTER'}();[/tt].
Also noted that the line [tt]print cisco_2651,"\n";[/tt] executes the sub, then prints its return value: calls to subs without parentheses nor &, I was pretty sure this wasn't allowed.
That's perl...

Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top