Hi! I'm having difficulty finding a place online which discusses this; if 
anyone has pointers (or an answer) I would appreciate it.

I would like to do something like the following:

        use List::MoreUtils qw/any all/;
        my $which = "any";
        my @list = (1, 0, 1);
        my $subref;
        if ($which eq 'any') { $subref = \&any; }
        elsif ($which eq 'all') { $subref = \&all; }

        my $result = $subref { $_ } @list;

The  problem I have is how to call the referenced subroutine. Because 'any' and 
'all' use prototypes to get a block as the first parameter, when called via the 
reference, it tries to create an anonymous hash. I've tried several different 
things:

        my $result = $subref->({ $_ }, @list);
        my $result = &{$subref} { $_ }, @list;
        my $result = $subref {; $_ }, @list;

and many variations thereof, but nothing seems to work. I get all sorts of ugly 
syntax errors.

My eventual goal is to have something like:

        my $lookup = {
                'any' => \&any,
                'all' => \&all,
                'none' => \&none,
                'notall' => \&notall,
        }

        if ( &{$lookup->{$test}} {$_} @$list );

Otherwise, I have to have an if-then-else (or given/when) structure, and a 
temporary variable, which is annoying...

Thanks,
Ricky


The information in this e-mail is intended only for the person to whom it is
addressed. If you believe this e-mail was sent to you in error and the e-mail
contains patient information, please contact the Partners Compliance HelpLine at
http://www.partners.org/complianceline . If the e-mail was sent to you in error
but does not contain patient information, please contact the sender and properly
dispose of the e-mail.


_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to