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 ... error
That 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.