FACTOID # 54: The Mall in Washington, D.C. is 1.4 times larger than Vatican City.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

FACTS & STATISTICS    Simple view

  1. Select countries to view: (hold down Control key and click to select several)

     

     

    Compare:

     

     

  1. Select fact or statistic: (* = graphable)

     

     

     

  2. (OPTIONAL) Compare to statistic: (both need to be graphable)

     

     

     

  3. View result as:

     

       
(OR) SEARCH ALL encyclopedia, stats & forums:   

Encyclopedia > Perl control structures

The basic control structures in Perl are similar to those used in the C or Java programming languages, but they have been extended in several ways. Programming Republic of Perl logo Perl, also Practical Extraction and Report Language (a backronym, see below), is an interpreted procedural programming language designed by Larry Wall. ... The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language The C programming language is a low-level standardized programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on the... Java is an object-oriented programming language developed initially by James Gosling and colleagues at Sun Microsystems. ...


Loops

 label while ( expr ) block label while ( expr ) block continue block label for ( expr1 ; expr2 ; expr3 ) block label foreach var ( list ) block label foreach var ( list ) block continue block 

where block is a sequence of one of more Perl statements surrounded by braces:

 { statement(s) } 

The label, which is terminated by a colon, is optional, but, if present, can be used by loop control statements.

  • The next statement moves to the next iteration of the loop identified by the label.
  • The last statement immediately terminates execution of the loop identified by the label.
  • The redo statement restarts the current iteration of the loop identified by the label.

Within nested loops, the use of the label with next, last and redo enables control to move from an inner loop to an outer one, or out of the outer loop altogether.


In the for statement, the semantics are similar to C. The first expression is evaluated prior to the first loop iteration; the second expression is evaluated prior to each iteration and the loop is terminated if it evaluates to boolean false; and the third expression is evaluated after each iteration, prior to deciding whether to perform the next. The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language The C programming language is a low-level standardized programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on the...


The use of a continue block after a while or foreach statement allows code to be executed after each iteration—even if the current iteration has been cut short by a next statement.


In foreach, the var is a scalar variable. It is optional, and, if omitted, the default loop iterator variable $_ can be used instead. The keywords for and foreach are synonyms and are always interchangeable.


In addition, any simple expression (that is, any non-block) can be executed repeatedly by following it by one of the qualifiers:

 while expr until expr 

which have the expected meaning.


When combined with the do construct, this provides a form of looping:

 do block while (expr); do block until (expr); 

The test is performed after each iteration, so that execution of the block is guaranteed to take place at least once.


Due to a linguistic foible of the Perl language, these are not regarded as true loops; the next, last and redo statements cannot be used to control a do block.


By itself, do executes a string of statements once, and evaluates to the value of the last statement:

 do block; 

Conditional statements

 if ( expr ) block 
 unless ( expr ) block 
 if ( expr ) block else block 
 if ( expr ) block elsif block else block 

where block is a sequence of one of more Perl statements surrounded by braces:

 { statement(s) } 

The expression is evaluated in a boolean sense. If it is numeric, any non-zero value is true. If it is a string, any string of non-zero length except "0" is true. "" and "0" are false. "0.0", "00", "-0", and "0 but true" are all true, even though they are all equivalent to zero when used for arithmetic; values like these are sometimes used when a successful operation needs to return 0.


An empty array or hash is evaluated in a scalar context, yielding false:

 my @a=(); print "True" if @a; 

Nothing is printed in this example.


Statement modifiers

For simple statements, while, until, if, unless and foreach can also be used as statement modifiers:

 statement while Boolean expression; statement until Boolean expression; statement if Boolean expression; statement unless Boolean expression; statement foreach list; 

The above modifiers cannot be nested, so this would be incorrect:

 statement if expression for list; #INCORRECT 

and should be written as one of:

 expression and statement for list; 
 for ( list ) { statement if expression } #Preferred form 

As noted earlier, the modifiers while and until can be combined with do to create a multiple-statement looping structure.


  Results from FactBites:
 
Perl - Wikipedia, the free encyclopedia (5477 words)
Perl is widely used in finance and bioinformatics, where it is valued for rapid application development, ability to handle large data sets, and the availability of many standard and third-party modules.
Perl is implemented as a core interpreter, written in C, together with a large collection of modules, written in Perl and C. The source distribution is, as of 2005, 12 MB when packaged in a tar file and compressed.
Perl developers rely on the functional tests to ensure that changes to the interpreter do not introduce bugs; conversely, Perl users who see the interpreter pass its functional tests on their system can have a high degree of confidence that it is working properly.
A Shortcut to Perl (2) (1224 words)
which is used in the three structures for controlling the number of times the loop is executed, is called the looping variable.
The commands in iterative structures will be executed in the same way until the value of a condition changes or the list of specified looping variable values becomes exhausted.
In Perl as we are using it right now, variables are defined automatically the first time when a variable is stored in them.
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.