Why do you make us waste our time verifying and fixing POC code accompanying your question?
It gives me a undefined subroutine &main:: called at ... errorThat code, as presented, gives me other errors. First
Scalar found where operator expected at foo.pl line 2, near ")
because of the "(yes I know....)" comment which isn't a comment. Fixing that,
syntax error at foo.pl line 4, near "..."
it chokes on ".... some code .....".
Please! Either post runnable code, or post something along with it like "this code doesn't run, can you help me fix it?"
Cleaning up your code to the point where it is at least runnable, I get
#!/usr/bin/perl -l $a = sub {return @_[0]}; $b = sub {return @_[0]+1}; if (0) { $i = $a; } else { $i = $b; } $number = 10; print &lala ($i); sub lala{ my $i = $_[0]; $res = &{$i}($number) ; #have also tried $res = $i->($number) with the same result } __END__ 11
which is kinda what I expected, and whithout errors.
There are major flaws with your code. Use strict, don't use $a and $b and so on. But now I've spent the time I had for that just to make your piece of code runnable - so sorry, others may hint you at those.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
In reply to Re: using reference to subroutine
by shmem
in thread using reference to subroutine
by kotoko
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |