Last active
January 1, 2016 01:29
-
-
Save jreisinger/8073485 to your computer and use it in GitHub Desktop.
The power of the do block
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/perl | |
use strict; | |
use warnings; | |
my $n = shift; | |
#my $desc; | |
#if ( $n > 0 ) { | |
# $desc = 'positive'; | |
#} elsif ( $n < 0 ) { | |
# $desc = 'negative'; | |
#} else { | |
# $desc = 'zero'; | |
#} | |
my $desc = do { | |
if ( $n > 0 ) { 'positive'; } | |
elsif ( $n < 0 ) { 'negative'; } | |
else { 'zero'; } | |
}; | |
print "$n is $desc\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment