Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to check, if an argument is passed in single quotes?

Is there a (best) way to check, if $uri was passed in single quotes?

#!/usr/local/bin/perl
use warnings;
use 5.012;

my $uri = shift;
# uri_check
# ...

Added this example, to make my problem more clear.

#!/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; 
like image 295
sid_com Avatar asked Dec 04 '22 21:12

sid_com


1 Answers

You can't; bash parses the quotes before the string is passed to the Perl interpreter.

like image 97
Blagovest Buyukliev Avatar answered Jan 11 '23 23:01

Blagovest Buyukliev