In other words, how can I check for equality in coderef?
The smartmatch operator does not work for obvious reasons (it will be considered CODE->(ANY) ), but I included it in the example to show what I need:
use strict; use warnings; use feature 'say'; sub pick_at_random { my %table = @_; return ( values %table )[ rand( keys %table ) ]; } my %lookup = ( A => \&foo, B => \&bar, C => \&baz ); my $selected = pick_at_random( %lookup ); say $selected ~~ \&foo ? "Got 'foo'" : $selected ~~ \&bar ? "Got 'bar'" : $selected ~~ \&baz ? "Got 'baz'" : "Got nadda" ;
perl
Zaid
source share