Created
May 7, 2012 09:02
-
-
Save eru/2626813 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
# こんな変数がありましたとさ | |
my $data = { param => "foo\n" }; | |
for (0..1) { | |
# 丁寧に?書くとこうなる | |
# if ($data->{param}) { | |
if (defined($data->{param})) { | |
print $data->{param}; | |
} else { | |
print '$data->{param}' . " is nothing.\n"; | |
} | |
$data->{param} = undef; | |
} | |
$data->{param} = "baz\n"; | |
for (0..1) { | |
# 1 line な感じで書くとこうなる | |
# if ($_ = $data->{param}) {} else { $_ = '$data->{param}' . " is nothing.\n"; } print; | |
if (defined($_ = $data->{param})) {} else { $_ = '$data->{param}' . " is nothing.\n"; } print; | |
$data->{param} = undef; | |
} | |
$data->{param} = "bar\n"; | |
for (0..1) { | |
# さらに, 存在しない時に出力しなくていいならば | |
# print if $_ = $data->{param}; | |
print if defined($_ = $data->{param}); | |
$data->{param} = undef; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment