Re: [問題] foreach if in one line

看板Perl作者時間14年前 (2010/06/02 15:26), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
※ 引述《dryman (dryman)》之銘言: : 請問有無可能將foreach和if判斷式寫在同一行呢? : 原始語意: : foreach (@arr){ : dosomething if expr; : } : 我試了 : dosomething if expr foreach @arr; : {dosomething if expr} foreach @arr; : 可是都失敗.. : 請問還有其他方法將if和foreach合併在一行嗎? 試看看用 do { dosomething if expr } foreach @arr; 如: do { print "$_\n" if ($_ % 2) } foreach (1..10); -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.114.64.130
文章代碼(AID): #1C1WUl6T (Perl)
討論串 (同標題文章)
文章代碼(AID): #1C1WUl6T (Perl)