A bit tidier and more reliable:
#!/usr/bin/perl -w
use strict;
use constant URL => 'openURL(%s, new-tab)';
use constant MAIL => 'mailto(%s)';
sub abs_path {
require File::Spec;
File::Spec->rel2abs(shift);
}
$_ = shift || '';
my $command =
m!^(?:ftp|http|file)://! ? sprintf URL, $_ :
-r($_) ? sprintf URL, 'file://'.abs_path($_) :
s!^(www\..+)!http://$1! ? sprintf URL, $_ :
s!^(ftp\..+)!ftp://$1! ? sprintf URL, $_ :
s/^mailto:// ? sprintf MAIL, $_ :
die "usage: $0 (filename|URL|mailto:foo\@bar.com)\n";
exec 'mozilla', -remote => sprintf($command, $_);
This checks -r early - thus, you can use it to invoke Mozilla on a directory called www.foo.bar/ without the scheme guessing getting in your way. It also handles URLs with ftp.* hosts nicely.
Makeshifts last the longest.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|