Statement Blocks

Domain Hosting image
Web Hosting
Dedicated server
ssl certificate
Web Design image
Email

A statement block is a group of statements surrounded by curly braces. Perl views a statement block as one statement, The last statement executed becomes the value of the statement block. This means that any place you can use a single statement like the map function you can use a statement block. You can also create variables that are local to a statement block. So, without going to the trouble of creating a function, you can still isolate one bit of code from another.

Here is how to use a statement block:

The statement block serves to emphasize that the inner code is set apart from the rest of the program. In this case, the initialization of $secondVar is a bit more complex than the other variables. Using a statement block does not change the program execution in any way; it simply is a visual device to mark sections of code and a way to create local variables.

Decision statements use the if keyword to execute a statement block based on the evaluation of an expression or to choose between executing one of two statement blocks based on the evaluation of an expression. They are used quite often. For example, a program might need to run one code section if a customer is female and another code section if the customer is male.



Domain Name Search

www.


Copyright (C) 2007. Web Domain design hosting. All rights reserved.