Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Executing a program from within a Perl Module in a non-standard path ($PATH/%PATH%)

by Anonymous Monk
on Mar 19, 2013 at 11:49 UTC ( #1024276=note: print w/ replies, xml ) Need Help??


in reply to Executing a program from within a Perl Module in a non-standard path

What would I do in this instance?

do what every operating system does, create an environment variable, like $PATH, and have it be a "list" of directories to search for binary executables. Since one exists for this purpose already, you could use it, but you don't have to
use lib ...;
use PathStuffer;
use File::Which;
my $frobnitz = which('checkout.pl');
system $frobnitz, ...


package PathStuffer;
use Env '@PATH';
use File::Find::Rule;
push @PATH, find( -file => name => qr{\.pl$} => in => $startdir);

See also Toolkit, String::ShellQuote/Win32::ShellQuote and/or IPC::System::Simple or IPC::Run/IPC::Run3 .. String::ShellQuote/Win32::ShellQuote and/or IPC::System::Simple or IPC::Run/IPC::Run3


Comment on Re: Executing a program from within a Perl Module in a non-standard path ($PATH/%PATH%)
Re^2: Executing a program from within a Perl Module in a non-standard path ($PATH/%PATH%)
by GoldElite (Sexton) on Mar 20, 2013 at 11:45 UTC

    Hmmm. It feels a little heavy-handed to modify the PATH for each potential script/executable after a recursive search, considering I technically know where they are stored (in the directory of the calling project/script, given a heirarchy of projects).

    On top of that, since I don't know it explicitly (that's pretty much the entire problem here!), $startdir will always be the cwd, too (or at least $FindBin::Bin), which would be redundant if PathStuffer is used multiple times (the search is probably a negligable impact in this day and age, but still. ;) ).

    Also, it's not always the case that a file will be a script (note that 'rdiff' is an executable binary), so just searching for ".pl" doesn't quite cover all use cases. Since *nix binaries don't really have naming conventions (and hence I'd have to search for ".*"), I'd necessarily be including every directory into the path to include it, which just makes me feel dirty. (It probably wasn't obvious that I'm using *nix boxes here, but I'd like to keep the code portable either way)

     

    That said, this is certainly still a viable option that I wouldn't have considered otherwise :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1024276]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2015-07-07 01:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (86 votes), past polls