Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Perl loop     - RHEL7 system making use of OpenStack mirror (Linux)

- Based on a complete solution RMI service to transfer large files (Programming)

- To help you easily protect the Linux System (Linux)

- Android Qemu GPS module (Programming)

- CentOS minimal network is unavailable resolved (Linux)

- OS X CAOpenGLLayer how to enable OpenGL 3.2 core profile (Programming)

- Linux environment variable configuration (Linux)

- Servlet life cycle code examples (Programming)

- Using IntelliJ IDEA Import Spark Spark latest source code and compile the source code (Linux)

- Profile Linux users login shell and login to read (Linux)

- How to install Wine 1.7.20 under Ubuntu or Linux Mint (Linux)

- Manager Docker browser (Server)

- grep regular expression (Linux)

- Vagrant failed to start, stuck in Waiting for VM to boot solution (Linux)

- On the Web application attack techniques Common (Linux)

- Android Scroller call mechanism and the relationship of computeScroll (Programming)

- Expert advice: Do not use the computer security IE browser (Linux)

- MongoDB version 3.2 WiredTiger storage engine performance tests (Database)

- Ubuntu under VirtualBox virtual machine serial port settings (Linux)

- MogileFS system installation configuration example (Server)

 
         
  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:      
 
- Ubuntu is not in the sudoers file problem solving (Linux)
- Subsequent binary search tree traversal sequence (Programming)
- Linux command to view the system status (Linux)
- Java data structures - order linear form of table ArrayList (Programming)
- Oracle 11g partition maintenance (two) - Coalescing Partitions (Database)
- C data types is how it is supported by most computer systems (Programming)
- Web database security tips (Linux)
- Recycle Bin function realization in Linux (Linux)
- ARM runtime environment built from scratch using QEMU emulator (Linux)
- ELKstack log analysis platform (Server)
- Use ARChon runtime environment to run Android apps on Ubuntu (Linux)
- CentOS 6.4 RPM install MySQL-5.6.22-1 (Database)
- Docker: Mirroring and container operations (Server)
- DRBD switchover (Server)
- MySQL composite partition (Database)
- Linux cron job (Linux)
- Install Python 3.3.4 under CentOS 6.4 (Linux)
- Ubuntu ADSL dial-up Internet access (Linux)
- Linux command in the dialog whiptail (Linux)
- Ora-00600 [fast hot Atkins soft _ that _ Oh, of course not _less_ profile] (Database)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.