Black-REN

好记性,不如烂笔头! Record your work !

scalar and list context in Perl

example:

@people = qw(  fred barney betty);

@sorted = sort @people; #list context: barney, betty, fred

$number = 42 + @people; # scalar context :45

@list = @people; #  a list of 3 people

$n = @people;# the number 3



Force list context to scalar context:

@rocks = qw( talc q f d );

$number = @rocks;

print  " the number is :", scalar @rocks, "hello";

print  " the number is : $number hello";

above are the same


ps: there is no corresponding functions to force list context. It turns out you never need it.

阅读更多
文章标签: perl
个人分类: Perl
上一篇List and Array in Perl
下一篇arguments for subroutine in Perl
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭