我想有条件地设置一个哈希键/值.我做了一些搜索,但似乎无法找到我的查询的正确条款.谢谢!
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $q = new CGI;
my $foo = $q->cookie('Foo');
my $uri = 'https://www.google.com';
#is there a way to do this more elegantly?
print $q->redirect(-uri => $uri, -cookie => $foo) if ($foo);
print $q->redirect($uri) unless ($foo);
Run Code Online (Sandbox Code Playgroud)
print $q->redirect(
$foo ? (-uri => $uri, -cookie => $foo)
: $uri
);
Run Code Online (Sandbox Code Playgroud)