LanX has asked for the wisdom of the Perl Monks concerning the following question:
Why does a (&) prototype only accept blocks or sub{} but not scalar coderefs?
I always thought that sub{} returns a scalar coderef.
See following code, line 36 shows a workaround from Ikegami.
But why the heck do I need an idempotent operation like \& ???
DB<32> sub fu(&) {print shift} DB<33> fu sub {} CODE(0x990f0a8) DB<34> $a= sub {} DB<35> fu $a #ERROR Type of arg 1 to main::fu must be block or sub {} (not scalar derefere +nce) at (eval 37)[/usr/share/perl/5.10/perl5db.pl:638] line 4, at EOF DB<36> fu \&$a #OK CODE(0x997f168)
Cheers Rolf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: coderefs and (&) prototypes
by ikegami (Patriarch) on Jul 28, 2009 at 02:08 UTC | |
by JadeNB (Chaplain) on Jul 28, 2009 at 21:20 UTC | |
by ikegami (Patriarch) on Jul 28, 2009 at 21:23 UTC | |
|
Re: coderefs and (&) prototypes
by LanX (Saint) on Jul 27, 2009 at 22:30 UTC | |
by JadeNB (Chaplain) on Jul 27, 2009 at 22:41 UTC | |
by LanX (Saint) on Jul 27, 2009 at 22:50 UTC | |
|
Re: coderefs and (&) prototypes
by JadeNB (Chaplain) on Jul 27, 2009 at 22:32 UTC | |
by ikegami (Patriarch) on Jul 28, 2009 at 01:42 UTC | |
by JadeNB (Chaplain) on Jul 28, 2009 at 17:59 UTC | |
by ikegami (Patriarch) on Jul 28, 2009 at 18:28 UTC | |
by LanX (Saint) on Jul 27, 2009 at 23:42 UTC |