sathish_cudd has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I have a script which use a sub routine from other pl file. Here are the the pl two codes.
# test.pl #!/usr/bin/perl use strict; use warnings; print "Hello, World...\n"; my $perl = "a.pl"; $perl->(10,20);
another .pl script.
# add.pl #!/usr/bin/perl use strict; use warnings; print "here\n"; return sub { my ($a , $b) = @_; return 0; };
if i ran the test.pl. it gives error as Can't use string ("a.pl") as a subroutine ref while "strict refs" in use at C:\Users\Sathish\Desktop\T\test.pl line 9. Please tell me what the error says. It would be great if i have an explanation. Thanks

Replies are listed 'Best First'.
Re: subroutine ref while "strict refs"
by tobyink (Canon) on May 12, 2012 at 12:20 UTC

    I think you wanted:

    my $perl = do "a.pl";

    You're missing the do.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: subroutine ref while "strict refs"
by ww (Archbishop) on May 12, 2012 at 12:41 UTC
Re: subroutine ref while "strict refs"
by choroba (Cardinal) on May 12, 2012 at 12:07 UTC
    The $routine->(10, 20) can be used if $routine contains a subroutine reference, i.e.
    $routine = sub { ... };
    You cannot use a file name instead of a subroutine reference.