关闭

scalar and list context in Perl

标签: perl
422人阅读 评论(0) 收藏 举报
分类:

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.

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:186740次
    • 积分:3213
    • 等级:
    • 排名:第11113名
    • 原创:106篇
    • 转载:224篇
    • 译文:0篇
    • 评论:2条
    文章分类