Greetings,
at first the short form of my question(s) - direct from my heart to the monestary public. After that, I provide some more background.
In short:I recently implemented some code inspired by a CPAN code example. Here is a snippet:
# add one handle and count it sub add_handle($$) { my $self = shift; my $easy = shift; $$self++; $self->SUPER::add_handle( $easy ); }
Why is it possible to use an object as a counter? Why does this not destroy the object? When I coded a similar thing for testing, the program breaks with the message "Not a scalar reference".
Background of the question:The example comes form the Net-Curl-package (see https://metacpan.org/pod/distribution/Net-Curl/lib/Net/Curl/examples.pod#Extracted-from-examples/02-multi-simple.pl). I made a successful API implementation along this example. But while adopting the example this special bit of code (the $$self++) looks so wired to me, that I choose to replace it by somewhat more readable ($self->{MULTI_HANDLER_COUNT}++).
But now I did some profiling on the API, and I ask myself, whether there is the essential difference between the official example code and the way I implemented the counting.
I hope someone can give me some deeper insights about the difference.
In reply to Why does $$self++ works? by rob25
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |