YouTip LogoYouTip

Perl If Statement

# Perl IF Statement [![Image 4: Perl Conditional Statements](#) Perl Conditional Statements](#) A Perl if statement consists of a boolean expression followed by one or more statements. ### Syntax The syntax is as follows: if(boolean_expression){ # Executes when boolean_expression is true} If the boolean_expression evaluates to true, the code block inside the if statement will be executed. If the boolean_expression evaluates to false, the first set of code after the if statement (after the closing brace) will be executed. ### Flowchart ![Image 5: if statement in Perl](#) ## Example #!/usr/bin/perl$a = 10; # Using if statement to check the boolean expression if($a<20){# Executes when boolean expression is true printf"a is less than 20n"; }print"value of a is : $an"; $a = ""; # Using if statement to check the boolean expression if($a){# Executes when boolean expression is true printf"Variable a is truen"; }print"value of a is : $an"; Executing the above program produces the following result: a is less than 20 value of a is : 10 value of a is : [![Image 6: Perl Conditional Statements](#) Perl Conditional Statements](#)
← Perl If Elsif StatementPerl Hashes β†’