Quantcast
Channel: Source.kohlerville.com » perl
Viewing all articles
Browse latest Browse all 3

Perl day 3: unless statement

$
0
0

Going off our if statement yesterday, I found that there’s something called the unless clause. According to the ifelseifelse website, the unless clause is the opposite of an if statement. I like their example of the following two statements being equivalent:
if (!$flag) { do_something();}
unless ($flag) { do_something();}

I’m used to using the ! for doing the opposite of a boolean statement, and probably will be doing that instead of using the unless statement. It is possible that some situations are better to use the unless statement that would provide better readability, like:
#!/usr/bin/perl
$a = 'taco';

unless ('$a' eq 'burrito') {
print "unless $a is a burrito, don't print this \n";
} else {
print "else it's a $a \n";
}


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images