在perl中逃脱双引号

时间:2016-11-06 21:55:33

标签: perl escaping double-quotes

当我将变量$ local_ntwk_ao_vpn(" X0 Subnet")传递给perl脚本时,它只需要" X0"和丢失的"子网"部分。我试图逃避双引号如下,但仍然没有奏效。非常感谢任何帮助。

#!/usr/bin/perl
use Expect;
#Assume the first 20 args are OK
my $local_ntwk_ao_vpn    = $ARGV[20];   # <-----"X0 Subnet"

# Telnet into the remote firewall
my $expect = Expect->new();
$expect->spawn("telnet 10.100.100.100 6025");
$expect->send("\n");
sleep(3);
$expect->expect( 10, 'User:' );
$expect->send("aUser\n");
$expect->expect( 10, 'Password:' );
$expect->send("password\n");
$expect->expect( 5, '>' );

$expect->send("configure\n");
$expect->expect( 5, '#' );

$expect->send("vpn policy site-to-site TESTVPN\n");
$expect->expect( 5, '#' );
$expect->send("network local name \"$local_ntwk_ao_vpn\"\n");  # <-- Still doesn't work here.
$expect->expect( 5, '#' );
$expect->send("exit\n");
$expect->send("end\n");
$expect->soft_close();

错误日志:

(edit-site-to-site[TESTVPN])# network local name "X0"
% Error encountered at '^' marker:
    network local name "X0"
                       ^^M
% Error: No matching command found.
(edit-site-to-site[TESTVPN])# exit

所需命令:

 (edit-site-to-site[TESTVPN])# network local name "X0 Subnet"

1 个答案:

答案 0 :(得分:5)

我认为你错误地认为X0 Subnet包含X0。它似乎只包含script.pl ... X0 Subnet ...

你使用过

吗?
script.pl ... 'X0 Subnet' ...

何时应该使用

num_array = [5, 3, 6, 12, 3, 5]
largest = max(num_array)
print("Max num: {}".format(largest))