有没有一种(最好的)方法来检查,如果$uri
被传递在单引号中?
#!/usr/local/bin/perl
use warnings;
use 5.012;
my $uri = shift;
# uri_check
# ...
为了更清晰地阐述我的问题,我添加了这个例子。
#!/usr/local/bin/perl
use warnings;
use 5.012;
use URI;
use URI::Escape;
use WWW::YouTube::Info::Simple;
use Term::Clui;
my $uri = shift;
# uri check here
$uri = URI->new( $uri );
my %params = $uri->query_form;
die "Malformed URL or missing parameter" if $params{v} eq '';
my $video_id = uri_escape( $params{v} );
my $yt = WWW::YouTube::Info::Simple->new( $video_id );
my $info = $yt->get_info();
my $res = $yt->get_resolution();
my @resolution;
for my $fmt ( sort { $a <=> $b } keys %$res ) {
push @resolution, sprintf "%d : %s", $fmt, $res->{$fmt};
}
# with an uri-argument which is not passed in single quotes
# the script doesn't get this far
my $fmt = choose( 'Resolution', @resolution );
$fmt = ( split /\s:\s/, $fmt )[0];
say $fmt;
perl so6249816.pl http://www.youtube.com/watch?v=TkqgnVW2_aA
(注意,没有任何shell引用),它确实会一直执行到第27行及其后面。你源代码中的注释说不会这样,解释一下这个矛盾之处。 - daximhttp://www.youtube.com/watch?v=BzSTSkhBCOc&feature=player_detailpage
,如果不加引号,它在我的尝试中无法工作。 - sid_com