Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: trouble taking reference of function

by samtregar (Abbot)
on Mar 03, 2009 at 21:22 UTC ( #747901=note: print w/replies, xml ) Need Help??

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";


Replies are listed 'Best First'.
Re^2: trouble taking reference of function
by ikegami (Pope) 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://747901]
[1nickt]: choroba Updated the PR, using Config instead of exposing the hackery. Using cpanfile-dump does not work to test, as shown in the earlier PR comment, even when using a binary built for a particular Perlbrew perl, the output seems to be
[1nickt]: ... from the system perl binary. Using cpanm --installdeps . does use the expected perl and tus the check acts correctly.
[choroba]: Nice, thanks. I'll look into it later, about to leave ATM.

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (15)
As of 2017-10-18 16:03 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (249 votes). Check out past polls.