Perl: reference to subroutine in external .pm file

Posted by Pmarcoen on Stack Overflow See other posts from Stack Overflow or by Pmarcoen
Published on 2010-04-06T13:48:52Z Indexed on 2010/04/06 13:53 UTC
Read the original article Hit count: 226

Filed under:
|
|
|

I'm having some trouble figuring out how to make a reference to a subroutine in an external .pm file.

Right now, I'm doing this :

External file

package settingsGeneral;    
sub printScreen {
    print $_[0];
}

Main

use settingsGeneral;    
my $printScreen = settingsGeneral::printScreen;
&$printScreen("test");

but this result into an error: Can't use string ("1") as a subroutine ref while "strict refs" in use

© Stack Overflow or respective owner

Related posts about perl

Related posts about subroutine