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

Perl/Basics/Boolean Logic/Statements/Golfing

From NetSec

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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";
}