美文网首页
Perl的字符串中数组内插

Perl的字符串中数组内插

作者: PETJO | 来源:发表于2021-06-14 18:42 被阅读0次

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";      #标量

相关文章

  • Perl的字符串中数组内插

    11. 字符串中数组内插 数组的内容可以被内插到双引号引起的字符串中,内插时,各个元素之间自动添加空格分隔。 数组...

  • perl继承的那些事

    Perl类的继承是通过@ISA数组实现的。@ISA数组不需要在任何包中定义,然而,一旦它被定义,Perl就把它看作...

  • Perl学习02数组和哈希使用

    实例介绍Perl中数组和哈希的使用。首发于本人公众号:pythonic生物人 更好的阅读体验请戳: Perl学习0...

  • ES6+ 数组方法

    1 、concat() 数组、字符串合并。 2、 at() 数组、字符串、类数组中添加.at()方法at()支持正...

  • Perl基础系列合集

    ​Perl学习01之标量数据 Perl学习02数组和哈希使用 Perl学习03之流程控制结构 Perl学习04之I...

  • Python 字符串处理常用方法

    去除掉字符串中特定符号 字符串转成数组 数组转字符串 字符串拼接

  • Perl数组

    数组变量以@开头,访问数组变量需要使用$+变量名称+索引值。 实例: 数组创建方式以@变量开头。使用qw定义数组。...

  • Perl 数组

    Perl 数组一个是存储标量值的列表变量,变量可以是不同类型。数组变量以 @ 开头。 创建数组 添加或删除数组元素...

  • 2.4

    数组API string() 把数组转为字符串 join('') 拼接,把数组中的元素拼接为字符串 concat(...

  • 习惯用法

    函数的默认参数过滤list val = positives = list.filter{ it > 0}字符串内插...

网友评论

      本文标题:Perl的字符串中数组内插

      本文链接:https://www.haomeiwen.com/subject/mbuoeltx.html