wperl via perl - detatching Tk scripts from the command line

Posted by NerdMachine on 2007-02-06 09:19

I was trying to figure out how to detach my Windows perl script from the command line such that when I run a Tk script, "foo.pl", the command line is not hung waiting for the GUI to exit. I found wperl.exe works quite well, but changing my .pl association will break my other perl scripts, and I don't want to go to the trouble of making a new association on all my deployments.

I found a better solution. I place this up front in my Tk scripts, and it switches over to wperl.

if ($^X =~ m,[\\/]perl\.exe$,) {
(my $wperlexe = $^X) =~ s/perl\.exe$/wperl.exe/;
exec ($wperlexe,$0,@ARGV);

I'm wondering if there are any unforeseen caveats to this technique. I can think of two:
1) startup time for launching another exe (minimal for most situations, but maybe this approach would be bad if wperl is used for web applications)
2) if the perl script is compiled to an exe, I'm not sure if $^X would work the same.