リストのつくり方(ひねくれ編)

Perl Cookbookより

my @list = (<< "EOD" =~ /^\s*(.+)/gm);
   I sit beside the fire and think
   of all that I have seen,
   of meadow-flowers and butterflies
   and summers that have been;
EOD

foreach (@list){
  print $_ . "\n";
}

その発想はなかったわww

# 出力結果
I sit beside the fire and think
of all that I have seen,
of meadow-flowers and butterflies
and summers that have been;

こゆこと.正規表現マッチのgオプションはリストを生成する,というしかけ.


しかし,
dan kogai氏がインタビューで「Perlはフリーダムすぐる」と言った理由(そう言ったのはMatz氏らしいけれど)ここにあり.という感じ.

Perl Cookbook: Solutions & Examples for Perl Programmers

Perl Cookbook: Solutions & Examples for Perl Programmers