perl - 有没有办法检查参数是否用单引号引起来?

标签 perl bash uri arguments expansion

是否有(最佳)方法来检查 $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; 

最佳答案

你不能; bash 在将字符串传递给 Perl 解释器之前解析引号。

关于perl - 有没有办法检查参数是否用单引号引起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6249816/

相关文章:

java - 如何在类路径有空格的 bash 中调用 java 程序?

php - 从 php 访问主题标签后的 URI 变量的最佳方法是什么?

regex - 将俄语单词的边框与\b匹配

perl - 是否可以将 sprintf 类型参数传递给 Perl 函数?

perl - 是否可以像 Template Toolkit 那样安全地访问嵌套数据结构中的数据?

java - URIBuilder build() 削减端口?

java - 防止 URI 导航

perl - 获取代码点的所有 Unicode 别名

php - 双引号在 PHP 的 shell_exec 和 sed 中不断被解析

linux - 如何在linux shell脚本输出中缩短文件路径