Skip to content

Instantly share code, notes, and snippets.

@jreisinger
Last active January 1, 2016 01:29
Show Gist options
  • Save jreisinger/8073485 to your computer and use it in GitHub Desktop.
Save jreisinger/8073485 to your computer and use it in GitHub Desktop.
The power of the do block
#!/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