in reply to Ftype/Associate
If this is what you're looking for, you could make a hash of known file extensions. Your functions could look like this (untested):assoc('.pl', 'd:\perl\bin\perl.exe'); # so you can run programs like this: run_cmd('c:\stuff\script.pl');
use vars qw/%extensions/; # keep known extensions here. %extensions = (); sub assoc { my ($extension, $prog) = @_; $extensions{$extension} = $prog; } sub run_cmd { my $cmd = shift; my $ext = ""; if ($cmd =~ /(\.\w+)$/) { $ext = $1; } # prepend interpreter for known extension if ($ext and exists $extensions{$ext}) { $cmd = "$extensions{$ext} $cmd"; } return `$cmd`; }
This loose code won't support arguments like myscript.pl --args, but that can be left as an exercise in string parsing.
I hope this is what you were asking!
Update: John M. Dlugosz's response above is probably more what you're looking for, upon reinspection of your question.
|
|---|