sid*_*com 4 bash perl uri arguments expansion
有没有(最好的)检查方法,如果$uri用单引号传递?
#!/usr/local/bin/perl
use warnings;
use 5.012;
my $uri = shift;
# uri_check
# ...
Run Code Online (Sandbox Code Playgroud)
添加了此示例,以使我的问题更加清晰.
#!/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;
Run Code Online (Sandbox Code Playgroud)
Bla*_*iev 12
你不能; bash在将字符串传递给Perl解释器之前解析引号.