I want to open a URL, such as http://www.example.com/
, at the end of a Perl script. I don\'t want to access it with WWW::Mechanize but actually show the web page to
You can use $^O
variable to identify a platform and use different commands for each OS.
For example:
sub open_default_browser {
my $url = shift;
my $platform = $^O;
my $cmd;
if ($platform eq 'darwin') { $cmd = "open \"$url\""; } # Mac OS X
elsif ($platform eq 'linux') { $cmd = "x-www-browser \"$url\""; } # Linux
elsif ($platform eq 'MSWin32') { $cmd = "start $url"; } # Win95..Win7
if (defined $cmd) {
system($cmd);
} else {
die "Can't locate default browser";
}
}
open_default_browser("http://www.example.com/");