scalar and list context in Perl

来源:互联网 发布:脑白金的网络推广案例 编辑:程序博客网 时间:2024/06/04 18:24

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.

原创粉丝点击