Odd variable naming question
Posted by Milo (Milo), 24 July 2003I've encountered a situation where I need to call a lot of other programs from a perl script, but need to check first that they are installed (in case the users can't/don't set this beforehand). What's needed is something like:
my @progs = qw(prog1 prog2 prog3); # etc. etc.
$"$_" = `which $_`;
# then, die if `which $-` =~ /not found/;
Obviously, the code above is complete rubbish, but it does express the sort of thing I'm after, i.e. the ability to call
system("$prog1 -options $file")
etc. later in the script. A shell script is not appropriate as I need to use lots of perl features (esp. bioperl) elsewhere in the script.
Or, have I got the wrong idea entirely?
Posted by admin (Graham Ellis), 24 July 2003You'll find lots of comments about eval and system and backquotes and special variables that return error statuses in the books ... however, these check whether something works when you try to run it and don't check earlier whether it exists. If you have an operating system with "which" available, yes, use code along the lines you have pseudo-coded. Here's a real code one I wrote:
and that gave me
Only problem to watch is that which returns a third format for shell built-ins, or it returns a "no" for them, depending on the operating system.
Posted by Milo (Milo), 25 July 2003Thanks. That almost does what I was after, so I also required users to supply the full path to the executables in a config file. The combination should do the trick.
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho