Skip to content

Instantly share code, notes, and snippets.

@mackee
Created August 17, 2014 05:01
Show Gist options
  • Save mackee/642fe4cd7d88d2610d5e to your computer and use it in GitHub Desktop.
Save mackee/642fe4cd7d88d2610d5e to your computer and use it in GitHub Desktop.
my @input_numbers = (1, 2, 4, 8, 16, 32, 64);
my @result = map {
my @digits = split //,$_; # $_を文字列として1文字ずつに分解する => 桁ごとに分解
if ($digits[-1] == 4) { # 一番最期の桁(=1の位)の桁がもし4であれば
@digits; #すべての桁をリストとして返す
} else { #そうでなければ
(); # なにも返さない
}
} @input_numbers;
# => (4, 6, 4)
foreach (@result) {
say;
}
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment