Skip to content

Instantly share code, notes, and snippets.

@ysasaki
Last active December 18, 2015 10:49
Show Gist options
  • Save ysasaki/5771505 to your computer and use it in GitHub Desktop.
Save ysasaki/5771505 to your computer and use it in GitHub Desktop.
return と return undef の違いを説明するときに使用したコード。list contextの場合に挙動が異なる
use utf8;
use strict;
use warnings;
use Test::More;
use Test::Name::FromLine;
sub return_only { return }
sub return_undef { return undef }
subtest 'scalar context' => sub {
my $only = return_only();
is $only, undef;
my $undef = return_undef();
is $undef, undef;
};
subtest 'list context' => sub {
my @only = return_only();
is_deeply \@only, [];
my @undef = return_undef();
is_deeply \@undef, [undef];
};
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment