in reply to callback or call now?
You say it's "a reference to a scalar", but don't you mean to say it's a reference to a code reference? You can add as many backslashes as you like, you only have to dereference them sufficiently to get at the underlying referent.
I think I understand, but I'm a bit puzzled by your terminology. Seems like a cool trick to me, let me see if I understand you correctly:
#! /usr/bin/perl -w use strict; sub foo { "this is foo" } sub bar { "this is bar" } my @later; sub do_it { my $ref = shift; if( ref($ref) eq 'CODE' ) { print "do it now: ", $ref->(), "\n"; } elsif( ref($$ref) eq 'CODE' ) { push @later, $$ref; } } do_it( \&foo ); do_it( \\&bar ); print "deferred ", $_->(), "\n" for @later;
Is that what you mean? If so, yeah, I like it.
|
|---|