タグ

ブックマーク / qiita.com/debug-ito (1)

  • map, grepの中でreturn - Qiita

    map, grepのブロックの中でreturnするとそのブロックではなくその外側のブロック(サブルーチンなど)からreturnする。 perl v5.14.2で確認。 use strict; use warnings; use feature qw(say); use List::Util qw(first reduce); sub custom1(&) { shift->(); } sub custom2(&@) { shift->(); } sub test_grep { my @a = (1); @a = grep { return 'from inside grep' } @a; return 'from outside grep'; } sub test_map { my @a = (1); @a = map { return 'from inside map' } @a; re

    map, grepの中でreturn - Qiita
    kiyo_hiko
    kiyo_hiko 2022/11/08
    "map, grepのブロックの中でreturnするとそのブロックではなくその外側のブロック(サブルーチンなど)からreturnする" → 怖い
  • 1