Perl @variable和$variablePerl 之间有什么区别?
我已经在变量名称之前读取了符号$和符号的代码@.
例如:
$info = "Caine:Michael:Actor:14, Leafy Drive";
@personal = split(/:/, $info);
Run Code Online (Sandbox Code Playgroud)
什么是包含变量之间的区别$,而不是@?
关于你的所有知识的Perl将与山被撞坏,当你不觉得这种语言的环境。
与许多人一样,您在讲话中使用单个值(标量)和集合中的许多东西。
因此,它们之间的区别是:
我有一只猫。 $myCatName = 'Snowball';
它跳到坐在床上的床上 @allFriends = qw(Fred John David);
你可以数一下 $count = @allFriends;
但根本无法计算它们,这导致名称列表不可计数: $nameNotCount = (Fred John David);
因此,毕竟:
print $myCatName = 'Snowball'; # scalar
print @allFriends = qw(Fred John David); # array! (countable)
print $count = @allFriends; # count of elements (cause array)
print $nameNotCount = qw(Fred John David); # last element of list (uncountable)
Run Code Online (Sandbox Code Playgroud)
因此,list与array并不相同。
有趣的功能是切片,您的大脑将在其中发挥作用:
这段代码是神奇的:
my @allFriends = qw(Fred John David);
$anotherFriendComeToParty =qq(Chris);
$allFriends[@allFriends] = $anotherFriendComeToParty; # normal, add to the end of my friends
say @allFriends;
@allFriends[@allFriends] = $anotherFriendComeToParty; # WHAT?! WAIT?! WHAT HAPPEN?
say @allFriends;
Run Code Online (Sandbox Code Playgroud)
因此,毕竟:
Perl具有有关上下文的有趣功能。您$和您@的签名,可以帮助Perl知道您想要什么,而不是您真正的意思。
$像s这样标量
@像a这样数组