Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Perl loop     - Linux server operating system security configuration (Linux)

- Java semaphores (Programming)

- JDK tools jstat (Linux)

- The oh-my-zsh into true my zsh (Linux)

- Ceph Source Analysis: Network Module (Server)

- VMware Workstation virtual machine Ubuntu achieve shared with the host (Linux)

- After Pydev installation, Eclipse does not display solutions (Linux)

- PXE + Kickstart automatically install CentOS 6.5 (Linux)

- Python2.7.7 source code analysis (Programming)

- Linux crontab (Linux)

- Disk Management LVM (Linux)

- Ubuntu installed Komodo editor by PPA (Linux)

- About Git (Linux)

- About Auto Layout and frame (Programming)

- Nginx request processing (Server)

- About AWR More Description (Database)

- How nodeclub constructed Docker image (Server)

- Linux shell script under the use of randomly generated passwords (Programming)

- PULL operation mechanism parsing XML Comments (Programming)

- The basic method RHEL6 (CentOS6) used in the source package compiled RPM: Upgrade OpenSSH articles (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:      
 
- Axel install plug under CentOS 5/6 acceleration yum downloads (Linux)
- ELKstack log analysis platform (Server)
- Install the Solaris 10 operating system environment over the network to sparc (Linux)
- Oracle user lock how to know what causes (Database)
- C ++ containers (Programming)
- Ubuntu 14.04 modify environment variables (Linux)
- HomeKit Human Interface Guidelines (Linux)
- Compiling source code Nginx module installation subs_filter (Server)
- Install Ubuntu Software Center App Grid (Linux)
- Unsafe reboot start (Linux)
- Java threads and thread pools (Programming)
- iptraf: A Practical TCP / UDP network monitoring tools (Linux)
- Ubuntu 15.04 and Ubuntu 14.04 installed Cinnamon 2.6 (Linux)
- Introduction to thread pooling and simple implementation (Programming)
- Shilpa Nair interview experience sharing RedHat Linux package management (Linux)
- Linux environment variable settings methods and differences (Linux)
- Python interview must look at 15 questions (Programming)
- MyCAT read and write separation of MySQL (Database)
- Samhain: Powerful intrusion detection system under Linux (Linux)
- linux system optimization and security configuration (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.