Questions about this topic? Sign up to ask in the talk tab.

Difference between revisions of "Perl/Basics/Boolean Logic/Statements/Golfing"

From NetSec
Jump to: navigation, search
(Created page with "The term '''golfing''' applies to condensing a boolean statement into one line. Golfing is typically used when you only need to execute one line of code for a boolean statement. ...")
 
 
(No difference)

Latest revision as of 02:19, 19 July 2012

The term golfing applies to condensing a boolean statement into one line. Golfing is typically used when you only need to execute one line of code for a boolean statement.

 
print "You are not 18 or older!\n" unless ($age >= 18);
 
  • Is essentially the same as:
 
print "You are not 18 or older!\n" if ($age < 18);
 
  • Is essentially the same as this un-golfed statement:
 
unless ($age >= 18) {
    print "You are not 18 or older!\n";
}