harangzsolt33 has asked for the wisdom of the Perl Monks concerning the following question:
Btw, I am trying to learn how to use "virtual functions" in Perl. Is there a better way than doing it like this?: my $Func = sub { ... };
use strict; use warnings; my $myFunction = sub { print "Hey, I am from Italy! @_\n"; }; printList(1, 2, 3, 4); $myFunction = sub { print "Hey, I am from Japan! @_\n"; }; printList(5, 6, 7); sub printList { print "\nprintList was called.\n"; &$myFunction->(); } exit; # # This program should print: # # printList was called. # Hey, I am from Italy! 1 2 3 4 # printList was called. # Hey, I am from Japan! 5 6 7 #
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: I'm getting some weird error
by jwkrahn (Abbot) on Dec 05, 2018 at 07:10 UTC | |
by harangzsolt33 (Deacon) on Dec 05, 2018 at 07:49 UTC | |
by Corion (Patriarch) on Dec 05, 2018 at 08:13 UTC | |
by LanX (Saint) on Dec 05, 2018 at 12:28 UTC | |
|
Re: I'm getting some weird error
by Corion (Patriarch) on Dec 05, 2018 at 07:10 UTC | |
|
Re: I'm getting some weird error
by haukex (Archbishop) on Dec 05, 2018 at 12:05 UTC |