Talk:Perl Programming/Functions

Use of "my" should be explained. (Done. Thanks, Dysprosia.)

No problem :) Dysprosia 04:58, 21 Apr 2004 (UTC)

Any chance you could cover calling a function by name at runtime as in

using strict; sub foo {  print "here"; } my $funcname = "foo"; $funcname;
 * 1) !/bin/perl

ps: the above code doesn't work in strict mode. I'm searching for the correct way to do it


 * No, the point of strict is to keep you from doing that. Don't do that.  Don't want to do that. --Randal L. Schwartz 22:51, 11 September 2006 (UTC)


 * Actually you can do that, and "There is more than one way to do it":

use strict; use warnings; sub foo { print "here\n"; } my $funcname = "foo"; $::{$funcname}; {  no strict qw(refs); &{$funcname}; }
 * 1) !/bin/perl


 * On the other hand, these are advanced techniques, those are highly advanced techniques, e.g., for those writing AUTOLOAD functions or writing test suite libraries. I don't think it is appropriate here. Ike 10:43, 8 November 2007 (UTC)