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

I am editing a script that uses strict which contains a subroutine that list the files in a $directory. I moved this subroutine into a seperate file and require it in the main script. Now the $directory, that was declared as "my" in the main script, doesnt seem to get passed to the subroutine because the script errors out, telling me that it cant open the directory "" (of course). I dont have much hair left to pull out, so somebody throw me a line, huh? please.

Replies are listed 'Best First'.
Re (tilly) 1: subroutines
by tilly (Archbishop) on May 22, 2001 at 22:03 UTC
    That script is written poorly. In the script put:
    sub list_dir { my $directory = shift; # Proceed as before }
    and then explicitly pass in your directory.

    Oh, and tell the author of that script for me that implicitly passing data into a subroutine through something you are using as a global variable is a really bad design. Which is why I am intentionally not telling you how to do it while preserving the current (very bad) API.