Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Perl loop     - Linux CentOS configuration SVN + SVN hook (Server)

- AngularJS - Custom instructions (Programming)

- The three-way division of the sorting algorithm Quicksort (Programming)

- Linux crontab use (Linux)

- Build the first ASP.NET 5 Web project in Mac OS X Yosemite 10.10.3 (Server)

- Linux top command to get started (Linux)

- C # C ++ Java interface type conversion (Programming)

- Linux stand-alone OGG synchronous Oracle 11g DB test (Database)

- Cobbler batch install Ubuntu / CentOS system (Linux)

- Linux and Unix systems really do network more secure (Linux)

- Git Advanced Tutorial (Linux)

- MySQL to manage multiple instances of method (Database)

- Linux operation and maintenance of the automated installation and deployment RHEL7.0 Cobbler (Linux)

- Spring + Log4j + ActiveMQ remote logging - Analysis of combat (Server)

- Getting Started with Linux system to learn: how to install the kernel headers on Linux (Linux)

- The difference Docker save and export commands (Linux)

- Talk about jsonp (Programming)

- Ubuntu 14.10 Server configuration wireless Internet access (Server)

- Zabbix monitors the status of TCP connections (Server)

- namespace mechanism Linux kernel analysis (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 Mint 17.2 64 bit installation Docker and management software seagull (Linux)
- Understanding the type in C ++ bitset (Programming)
- Talking about the shortcomings and deficiencies of the firewall (Linux)
- How to Install Redis server on CentOS 7 (Server)
- Why you can have JavaScript string method (Programming)
- Shell programming entry (Programming)
- Storm how to assign tasks and load balancing (Programming)
- Build your own CA services: OpenSSL command line CA Quick Guide (Server)
- OpenSUSE GPG Comments (Linux)
- Some practical tips Linux (Linux)
- Linux print file and send mail (Linux)
- IronPython and C # to interact (Programming)
- vector C ++ sequence containers (Programming)
- Embedded Linux to solve the problem in the time zone (Linux)
- How to fix apt-get update can not add a new CD-ROM error (Linux)
- Installation through the network Debian 7 (Wheezy) (Linux)
- Try the command ip, ifconfig is obsolete under Linux (Linux)
- Linux Getting Started tutorial: Borrow Windows fonts in Ubuntu 14.10 (Linux)
- Ubuntu system grub repair method (Linux)
- Java implementation linear table - represents the order of representation and chain (Programming)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.