加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

打卡13-perl function-reverse/chop

发布时间:2020-12-15 23:56:27 所属栏目:大数据 来源:网络整理
导读:1 Which one of the following is a major difference between the chop and chomp functions? chomp and chop Chomp cuts off only the current input record separator value; chop cuts off any character. for example: $a="abcde"; chomp($a); chop($a)

1

Which one of the following is a major difference between the chop and chomp functions?
chomp and chop
Chomp cuts off only the current input record separator value; chop cuts off any character.
for example:
$a="abcde";
chomp($a);
chop($a);-------abcd

2 reverse

reverse 函数
例子:
print reverse <<EOF
hello WoRLD
This is teXt
EOF
结果:
DLEoW oLleh
tXet si sihT

this is tricky. Because scalar(reverse())
scalar ask reverse to be in scalar context. So reverse will reverse everything!!!
In list context,returns a list value consisting of the elements of LIST in the opposite order.
In scalar context,concatenates the elements of LIST and returns a string value with all characters in the opposite order.

print join(",",reverse "world","Hello"); # Hello,world?
print scalar reverse "dlrow,"olleH"; # Hello,world
First is List context. The second is scalar context.

It also interesting when you reverse a hash.
my %a = reverse %b;
See what happened?
the key->value changed to value->key.
If same value exists,only one of them kept.

my %a=('a'=>1,'b'=>2); my %b = reverse %a; foreach my $key(keys %b){ ? print "$key -> $b{$key}n"; }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读