[英]print one part of a array in double quotes
What I'm trying to do is have my array names print out in a single line Andrew "Andy" Kaufman.我想要做的是在一行中打印出我的数组名称 Andrew "Andy" Kaufman。 This is what I have so far.
这是我到目前为止。
#DEFINE AN ARRAY
@names = (Andrew,Andy,Kaufman);
#printing the array
print "@names";
#!/usr/bin/env perl
use strict;
use warnings;
#DEFINE AN ARRAY
my @names = ("Andrew","Andy","Kaufman");
$names[1] = "\"$names[1]\"";
print "@names";
This will modify the array too.这也会修改数组。
even though Sobrique has already ansewered, another possible solution would be即使 Sobrique 已经回答,另一种可能的解决方案是
#DEFINE AN ARRAY
my @names = qw(Andrew "Andy" Kaufman);
#printing the array
print "@names";
or或者
#DEFINE AN ARRAY
my @names = qw(Andrew Andy Kaufman);
#or
#my @names = ("Andrew","Andy","Kaufman");
#printing the array
print "$names[0] \"$names[1]\" $names[2]";
I think your main trouble was to print a double quote, you simply have to escape it with a backslash.我认为您的主要麻烦是打印双引号,您只需要用反斜杠将其转义即可。 it's a way to say to perl "hey this is not the actual end of string, this is a character I want to be in the string"
这是对 perl 说的一种方式“嘿,这不是字符串的实际结尾,这是我想出现在字符串中的一个字符”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.