Perl学习笔记【Learning Perl】【更新中】

来源:互联网 发布:淘宝买处方药药师回拨 编辑:程序博客网 时间:2024/05/01 21:51

1. 一个给定的表达式在不同的上下文中其含义是不同的。

    例如,一个数组的“name”,在列表context 中,它返回列表元素;在标量context 中,

    它返回数组元素的个数。

     

    @people = qw( fred barney betty );

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

    $number = 42 + @people;   #标量context:42+3,得到45

     

    我曾经犯的一个错:

    @arr = qw/a b c d e f g/;

    print @arr."hello";#返回的是7hello

    print @arr, "hello";#返回的是abcdefghello

     

2. 待续

原创粉丝点击