perl – 有没有办法检查,如果参数是用单引号传递的?
发布时间:2020-12-15 23:27:48 所属栏目:大数据 来源:网络整理
导读:如果用单引号传递$uri,是否有(最佳)检查方法? #!/usr/local/bin/perluse warnings;use 5.012;my $uri = shift;# uri_check# ... 添加了此示例,以使我的问题更加清晰. #!/usr/local/bin/perluse warnings;use 5.012;use URI;use URI::Escape;use WWW::YouTub
如果用单引号传递$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解释器之前解析引号.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |