1 2 3 4 5 6 7 8 9 10 11 12
my @strings = ( 'http://foo.example.org/', 'mms://bar.example.org/', 'https://foobar.example.org/', 'http:///tmp/foobar.txt', ); for my $str ( @strings ) { if ( substr($str,0,8) eq 'http:///' ) { print "Treffer 'http' bei $str\n"; } }
1 2 3 4 5 6
my $string = 'http://blah/'; my ($proto) = $string =~ m#^([a-z]+)://#; if (defined $proto) { print "Dies ist ein $proto-Link\n"; }
1 2 3 4 5
use URI; my $u = URI->new("http://foo.example.org/"); say $u->scheme; __END__ http
cdda://, alsa://
satell:// oder dvb://
1
2
3
4
$ perl -MURI -wle 'my $uri = URI->new( "alsa://" ); print $uri->scheme;'
alsa
$ perl -MURI -wle 'my $uri = URI->new( "cdda://" ); print $uri->scheme;'
cdda
$ perl -MURI -wle 'my $uri = URI->new("dvb://tv.mydomain.com:11300/rsat.ts"); print $uri->host;'
$ perl -MURI -wle 'my $uri = URI->new("ftp://tv.mydomain.com:11300/rsat.ts"); print $uri->host;'
$ perl -MURI -wle 'my $uri = URI->new("dvb://tv.mydomain.com:11300/rsat.ts"); print $uri->host;'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#! /usr/bin/perl use strict; use warnings; use URI; my $uri = URI->new("dvb://tv.mydomain.com:11300/rsat.ts"); if ( !$uri->can('host') ) { # treat it like a http scheme, save the old one my $scheme = $uri->scheme('http'); print $uri->host; # restore old scheme $uri->scheme($scheme); } __END__
1 2 3 4 5 6 7 8 9 10 11 12
#! /usr/bin/perl use strict; use warnings; use URI; my $uri = URI->new("dvb://tv.mydomain.com:11300/rsat.ts"); print $uri->host; # erzeuge neues URI Scheme package URI::dvb; use parent "URI::http"; 1;
Guest Graf Herschel[...]
Noch eine kurze Frage.
Gibt es in diesem Fall einen Unterschied zwischen:
if (defined $proto)
oder
if ($proto)
?