Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Perl loop     - Debian 8.2.0 (Jessie) fast clean installation tutorial (Linux)

- Linux server data backup (Server)

- Ubuntu users install the Download Manager software Xdman 5.0 (Linux)

- Linux Network Programming --IP packet format Detailed (Programming)

- Run two MySQL service on one server (Database)

- To install the Oracle 10.2.0.1.0 process notes on Oracle Linux 4u4 (Database)

- Ubuntu 14.04 configure JDK1.8.0_25, switchable version (Linux)

- CentOS / Linux SWAP partitions added (Linux)

- About Auto Layout and frame (Programming)

- Log analysis is done with Grafana Elasticsearch (Server)

- Tree Traversals Again (Programming)

- ogg Oracle to SQL Server 2005 to achieve synchronization (Database)

- Ubuntu install perfectly handsome terminal Guake 0.8.1 (Linux)

- Shell programming entry (Programming)

- MongoDB Learning the notes (Database)

- Partition contrast manifestations under Windows and Linux (Linux)

- RHEL5.8 physical opportunities to Read-only file system (Linux)

- CentOS 7.0 Automatic installation CD-ROM production Comments (Linux)

- Linux how to prohibit the use of Ping command (Linux)

- RocketMQ Message Queuing simple deployment (Linux)

 
         
  Perl loop
     
  Add Date : 2017-09-18      
         
       
         
  While loop syntax:

while (some_expression) {
 statment_1;
 statment_2;
 ....
}

When the program executes the statement while, first check the control statements (some_expression), if it is true, the loop body will be executed once, so repeated constantly perform, know the control statement is false, then stop while cycling

Example:

#! / Usr / bin / perl -w
$ Number = 10;

while ($ number> 0) {
 print ( "number is $ number \ n");
 - $ Number;
}

until loop syntax

until (some_expression) {
 statment_1;
 statment_2;
 ...
}

And while statements contrary, some_expression false the loop body is executed, that is true stop the loop
Example:


#! / Usr / bin / perl -w
$ Number = 10;


until ($ number < = 0) {
 print ( "number is $ number \ n");
 - $ Number;
}

do while loop and do until loop syntax

do while or do until loop the loop executed at least once before the condition is checked.

do {
 statment_1;
 statment_2;
 ...
} While (some_expression);

do while loop, the conditional expression is false then the loop ends

do {
 statment_1;
 statment_2;
 ...
} Until (some_expression);

do until loop, the conditional expression is true then the end of the loop

for loop
for statement is mainly used to determine the number of cycles, the syntax is as follows:

for (in fact statement; test statement; stepping statement) {
 statment_1;
 statment_2;
 ....
}

First, the system will perform the initial statement. Usually you can assign values to variables here, but this is not mandatory, or even nothing to write, but to write or semicolon. If the value of the test the statement is true, the loop is executed once, then execute step statement.

foreach loop

foreach loop can receive a list, which will be assigned to a primary data as a parameter of a scalar variable, and the implementation of an effective assignment of each block of code statements. Its syntax is as follows:

foreach $ i (@some_list) {
 statment_1;
 statment_2;
 ....
}

Example:

#! / Usr / bin / perl -w

foreach (1..10) {
 print "";
 print;
}

print "\ n";

Leaping list any statement foreach list is used, not necessarily the array variable, you can not even write a scalar variable, so perl using the default variable $ _. If you do not specify any value to print, it will print out the contents of $ _.

If the list of values should be used where the use of a real variable, the function returns a list of substitution, then perl will be used in a loop to pass variables as aliases variables, rather than just copy values only. Thus, if you change the scalar variable in a loop, the corresponding element in the list will be changed accordingly. E.g:


#! / Usr / bin / perl -w


@ X = (1..10);
foreach $ num (@x) {
 
 $ Num + = 10;
}
print "@x";
print "\ n";

foreach after the implementation, the value of the array @x changed.
     
         
       
         
  More:      
 
- Linux System Getting Started Learning: Linux command in w (Linux)
- Linux development environment to build and use the directory structure and file --Linux (Linux)
- CentOS7 + Redis Live Installation and Configuration (Linux)
- Installation Sublime Text 3 (Build 3065) text editor in Ubuntu (Linux)
- Oracle 11g upgrade PSU detailed steps (Database)
- Java Builder mode (Programming)
- CentOS 6.4 of cron scheduled task configuration (Linux)
- Seven Steps to Help Google Chrome Speed - (Linux)
- U disk to install Windows and Ubuntu 15.04 dual system (Programming)
- Spring REST Exception Handling (Programming)
- CentOS Linux firewall configuration and Close (Linux)
- Vi editor Introduction (Linux)
- Talk about the Linux folder permissions issue again (Linux)
- Performance issues under CentOS 6.5 VLAN devices (Linux)
- Java in the final qualifier (Programming)
- iOS persistence of data archiving NSKeyedArchiver (Programming)
- Git version rollback (Linux)
- Security enhancements in Ubuntu ssh service (Linux)
- grep command output highlighted word (Linux)
- Access clipboard content across multiple vim instances in a terminal (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.