Or, at the risk of beating a dead horse:
#!/usr/bin/perl -w
use strict;
my $url = shift || '';
$url =~ /^(.*?):/;
my $protocol = lc($1);
my %handlers = (
'http' => \&http_handler,
'ftp' => \&ftp_handler,
'https' => \&http_handler,
'ftps' => sub { print "FTPS supported in next version.\n"; }
);
if ( exists $handlers{$protocol}) {
undef &Handler;
*Handler = $handlers{$protocol};
Handler($url);
} else {
UnHandler($url);
}
sub http_handler {
print "HTTP handler: ", shift, "\n";
}
sub ftp_handler {
print "FTP handler: ", shift, "\n";
}
sub UnHandler {
print shift, " - Protocol not supported\n";
}
-will
Gary Stainburn wrote:
>
> Hows about:
>
> SWITCH:for ($url=~/^(\S*):/) {
> /http/ || /HTTP/ && do { print "you chose http\n"; last ; };
> /ftp/ || /FTP/ && do { print "you cose ftp\n"; last ; };
> print "you chose summat else ($_)\n";
> };
>
> Gary
>
> On Wednesday 18 July 2001 1:45 pm, Sparkle Williams wrote:
> > I'm trying to write a perl script that can distinguish between http and ftp
> > files. I got it to work on my UNIX system using case, but I can't seem to
> > get it to function correctly when I switch to using if-then on my Windows
> > NT system. Does anyone have any ideas as to how I can correctly adjust my
> > script?
> >
> > #!/usr/bin/perl
> > print "Enter the full name of the file you are looking for. " ;
> >
> > $url=<STDIN>;
> >
> > chomp ($url);
> >
> > if ($url) { HTTP:// };
> >
> > print " You have chosen a file of type HTTP! ";
> >
> > elsif ($url) { FTP:// } ;
> >
> > print "You have chosen a file of type FTP! ";
> > else ($url) {*} ;
> >
> > print "I'm sorry. This program does not support that type of
> > file." ;
> > _________________________________________________________________________
> > Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
> --
> Gary Stainburn
>
> This email does not contain private or confidential material as it
> may be snooped on by interested government parties for unknown
> and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]