next up previous
Next: make Up: Scripting Previous: shell

perl

Now let's try perl. This version allows you to enter the relative path of a local file. It'll automatically prepend file: and the current directory if there's no protocol specified.

#!/usr/local/bin/perl -w
use Cwd;
die("usage: open-url URL\n") if ($#ARGV != 0);
$browser = exists $ENV{'BROWSWER'} ? $ENV{'BROWSWER'} : 'netscape';
$url = pop(@ARGV);
if (not $url=~m/^(?:file|gopher|https?|mailto|news):/)
  {$url = 'file:' . ($url=~m|^/| ? $url : cwd."/$url")}
(system($browser,@ARGV,'-remote',"openUrl($url)")>>8)
  and exec($browser,@ARGV,$url);

Soapbox: perl has oodles of very attractive features: unlimited length arrays and hashes; supports object oriented modules; protected namespaces; turbo studly regular expressions; system interface commands; taint security checking; simplified data types; and ... (time passes, people fall asleep) ... and on-the-fly compilation.



Reece Kimball Hart
1998-03-18