Perl的字符串中数组内插

2021-06-14  本文已影响0人  PETJO

11. 字符串中数组内插

my @rocks = qw/ flintstone slate rubble /;
print "quartz @rocks limestone\n";

print "Three rocks are: @rocks.\n";

my @bedrock = qw/ slate rubble /;
print "fred@bedrock.edu\n";
print "fred\@bedrock.edu" . "\n";
print 'fred@bedrock.edu' . "\n";

my @fred = qw( hello dolly);
my $y = 2;
my $x = "This is $fred[1]'s place.\n";
print "$x";

$x = "This is $fred[$y-1]'s place.\n";
print "$x";

my $z = 2*4;
print $z . "\n";
$x = "This is $fred[$z-1]'s place.\n";
print "$x";

@fred = qw( hello dolly);
my $fred = "right";

print "this is $fred[1].\n";       #数组索引;
print "this is ${fred}[1].\n";     #标量,用花括号避开歧义
print "this is $fred"."[1].\n";    #标量
print "this is $fred\[1].\n";      #标量
上一篇 下一篇

猜你喜欢

热点阅读