Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: HASH value as a subroutine call

by Perlbotics (Canon)
on Oct 21, 2012 at 10:49 UTC ( #1000199=note: print w/replies, xml ) Need Help??


in reply to HASH value as a subroutine call

You need to populate the hash with code-references (\&sub).

Try:

use strict; # my $code_ref = {'SUM', 'sum'}; my $code_ref = {'SUM', \&sum}; sub sum($$){...} # do you really need ($$) ? That is rarely useful. # ($codes->{'SUM'})->(4,5); # $codes? You mean $code_ref? $code_ref->{'SUM'}->(4,5);

Replies are listed 'Best First'.
Re^2: HASH value as a subroutine call
by AnomalousMonk (Canon) on Oct 21, 2012 at 11:46 UTC
    sub sum($$){...} # do you really need ($$) ? That is rarely useful.

    Rarely useful, often misused, and in this case (in which prototypes are not checked at all) totally useless. E.g.:

    >perl -wMstrict -le "sub sum ($$); ;; my $codes = { 'SOFT' => 'sum', 'HARD' => \&sum, }; ;; $codes->{HARD}->('HARD', 1, 2, 3, 4); ;; { no strict 'refs'; $codes->{SOFT}->('SOFT', 9, 8, 7, 6); } ;; sub sum ($$) { print qq{(@_) arguments: }, scalar @_; } " (HARD 1 2 3 4) arguments: 5 (SOFT 9 8 7 6) arguments: 5

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000199]
help
Chatterbox?
[thezip]: G'day all. Apparently Strawberry Perl has issues with deploying Spreadsheet::XLSX for Perl 5.24.1. I need this module to maintain compatability with an existing script. I'm new to Strawberry -- is there a safe way to manually deploy this?
[MidLifeXis]: Where is it hanging up?
[MidLifeXis]: ISTR having a couple of issue based on undeclared dependencies around the time I was looking at that module on my last project, but cannot say if that was the module that I had the dependency issues with.
[MidLifeXis]: (5.22 at that time)
[MidLifeXis]: Yeah, I know, really helpful :-)
[Corion]: If all else fails, Spreadsheet::XLSX should be "installable" by manually copying the files, provided that the prerequisites are met

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2017-03-23 17:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (290 votes). Check out past polls.