有没有办法检查,如果参数在单引号中传递?

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解释器之前解析引号.

  • @sid_com似乎很清楚这是一个"XY问题"(http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)所以更好的问题是"为什么你认为知道如何引用shell args将帮助你解决你真正的(未说明的)问题是什么?" IOW,为什么你认为你需要知道它是如何被引用的? (4认同)
  • @Grrrr:嗯,我说bash因为它在问题的标签中. (2认同)