quote : http://note.tcc.edu.tw/217.html

1. 將 qw LIST 中的數值開根號 x10
my @array = map { sqrt($_)*10 } qw/50 60 70 75 91 18 39 66/;

2. 將 0-9 平方後丟到 @array中 @array=(0,1,4,9,16,25,36,49,64,81)
my @array = map { $_ ** 2 } (0..9);

3. 將清單加上@domain name,注意這裡的 ‘@note.tcc.edu.tw’ 是以單引號括起,否則用雙引號會把 @note 視為陣列
@user= (‘ axer’, ‘john’, ‘peter’, ‘lee’);
@mail = map {  $_ .  ‘@note.tcc.edu.tw’ } @user;

結果 @mail= ( ‘ axer@note.tcc.edu.tw’, ‘john@note.tcc.edu.tw’, ‘peter@note.tcc.edu.tw’, ‘lee@note.tcc.edu.tw’ );

4. 下例map 將@m 陣列中的字串空白移除,@m 本身被改變
@m=(”   www”,  “facility “, ” mail “);
map { s/s+//g } @m;
print “@m
“;

結果 www facility mail

Related posts 相關文章
2020 年迎來了 PHP 8 與 Perl 7
More...
安裝 perl 5.8.1 版本 – 草記
More...
perl 備註
More...
perl 隨機產生 password 密碼
More...

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。