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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Subroutine problems
by Corion (Patriarch) on Jul 30, 2007 at 15:23 UTC

    You don't tell us what errors you get. Also, you have no error checking when you eval your script. Even more, the code is horribly ugly and unformatted and not at all self-contained so it's quite hard to guess what it does. I'm rewriting it with more legible syntax and some added error checking - that might help you to diagnose the exact error you get:

    subfile('iocommon'); sub subfile { my($f)=@_; my($w); # %GOT_HA seems to be a variable emulating %INC maybe? if(!$GOT_HA{$f}){ # where do $my_base_loc, $subslocation and $ds come from? # is that a case for using File::Spec instead? $f=("$my_base_loc$subslocation$ds$f.sub"); # you need error handling here in case the file is not found: # Are $t and $rep global variables? What are they used for? $t=open (IE,"$f") or die "Couldn't open '$f': $!"; $rep=($t)?'OK':$!; # What does that do? Maybe you want to look in that log for th +e error report? db("subfile $f",$rep); # Are you using strict; at all? You really should! # This whole section is likely better written as # my $w = do { local $/; <IE> }; @tt=<IE>; close(IE); while(@tt){ $l=trim(shift @tt); $w.=$l."\n"; } eval($w); if (my $err = $@) { die "Error in evaluating '$f': $!"; }; $GOT_HA{$f}=1; } }

    Update: The below recommendations of using do or Module::Pluggable sound very good to me and especially do or require should have occurred to me had I looked at the bigger picture...

Re: Subroutine problems
by Trizor (Pilgrim) on Jul 30, 2007 at 15:37 UTC

    It seems like you're attempting to re-implement the require function, loading a library at runtime, or the do FILE use of do, you might want to look into perl's variety of library loading functions before attempting to debug this.

    It seems you need a library, you might want to consider reading perlmod and perlmodlib for information on writing libraries.