http://qs321.pair.com?node_id=747901


in reply to trouble taking reference of function

Perl's builtins aren't generally made available as subs you can take a reference to. This works though:

my $foo = sub { sin(@_) }; print $foo->(0.5), "\n";

-sam

Replies are listed 'Best First'.
Re^2: trouble taking reference of function
by ikegami (Patriarch) on Mar 03, 2009 at 21:25 UTC
    Beware of prototypes when dealing with functions and named operators.
    $ perl -wle'print sin(0.5) == sub { sin(@_) }->(0.5) ?1:0' 0 $ perl -wle'print sin(0.5) == sub { sin($_[0]) }->(0.5) ?1:0' 1

    Update: Added code.

      Huh? Why does that happen?

      And you didn't even know bears could type.