![]() |
|
Welcome to the Monastery | |
PerlMonks |
Re: Trying to Understand Callback(s)by shmem (Chancellor) |
on Nov 24, 2017 at 00:29 UTC ( [id://1204184]=note: print w/replies, xml ) | Need Help?? |
...but I don't really quite get the idea of callbacks, and particularly I don't understand the syntax. Well, it's not just quite like with a phone - you ring up somebody, they hang up and call you - but rather a way to parametrize a subroutines execution chain via a subroutine reference (like a function pointer). The called sub may have been compiled into any context, and the compilation rules of that context apply. And what ikegami said. I don't really get the first line of the get_callback routine either, when nothing appears to be being passed across
It gets something passed across but discards it. A sub routine called as a method ($thingy->routine(@args)) by something ($thingy - irrelevant whether $thingy is a literal, a blessed reference, a scalar holding a string, or an expression which resolves to a package or a blessed reference) gets passed the invocant as its first parameter in @_. So, having this preamble
the following call expressions are all equivalent:
More on differences between subroutine calls either as function or method: perlsub, perlmod, perlref. The expression
is just a fancy way of saying
The subroutine get_callback you quoted just seems not to care at all about it's invocant, but nonetheless expects to be called as a method. Hmm, code smell...
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
In Section
Seekers of Perl Wisdom
|
|