Because you're not passing any arguments in &$myFunction->() but are expecting to see the arguments to printList get output, I'm guessing that perhaps you were trying to call the sub like one would in &foo;, which leaves the original @_ unchanged (see perlsub). However, this is nowadays not considered a good practice, as leaving @_ unchanged can also easily lead to mistakes. Plus, using the &foo syntax avoids prototype checking, which is also something that one should only do if one knows what one is doing. If you do want to make use of the & functionality for whatever reason, the correct syntax is &$myFunction; - but as the others have said, it's usually better to be explicit and use $myFunction->(@_); instead. See also perlreftut and perlref on using references.
Is there a better way than doing it like this?: my $Func = sub { ... };
I'm not sure what you mean with "virtual functions" in this context, but my $Func = sub { ... }; is basically "the" way to create an anonymous subroutine and store a reference to it.
In reply to Re: I'm getting some weird error
by haukex
in thread I'm getting some weird error
by harangzsolt33
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |