Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Perl loop     - Install JDK 1.7 + Eclipse in CentOS 6.4 in (Linux)

- To protect the temporary files for Linux security (Linux)

- Chkconfig command Detailed service is added and shut down the system in two ways to start service under Linux (Linux)

- Installation of Python2.7.10 under CentOS 6.4 (Linux)

- RHEL7 unattended automatic installation DHCP + TFTP + SYSLINUX + TFTP + Kickstart (Linux)

- Five programming fallacy (Programming)

- pscp use Detailed Windows and Linux each file transfer tool (Linux)

- Linux instructions and examples GPG encryption and decryption (Linux)

- Keepalived achieve high availability Nginx Reverse Proxy (Server)

- Use OpenSSL to generate a certificate (Linux)

- Linux virtual machine settings network, hostname ssh access (Linux)

- SQL Beginner Guide (Database)

- The Java way to stop a thread of execution (Programming)

- RHEL 6.4 installed MySQL 5.6.27 (Database)

- Based Corosync + Pacemaker + DRBD + LNMP Web server to achieve high availability cluster (Server)

- Simple steps allows you to build a more secure Linux server (Linux)

- MySQL Tutorial: Philosophical Reflections on the unauthenticated user (Database)

- Android Dynamic efficiency articles: a brilliant Loading Analysis and Implementation (Programming)

- Formatted output printf command (Programming)

- PHP generates a random password several ways (Programming)

 
         
  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:      
 
- Ceph Source Analysis: Network Module (Server)
- Android HTTP request with Get Information (Programming)
- Ubuntu resolve sudo: source: command not found error (Linux)
- JDK tools jstat (Linux)
- Unetbootin make use U disk loading Linux system (Linux)
- MongoDB collection data migration to MySQL database (Database)
- Ubuntu 12.04 LTS installation configuration JDK1.6.0_45 (Linux)
- Red Hat Enterprise Linux configuration VNC multi-user access methods (Linux)
- Detailed Linux su command to switch users Mistakes (Linux)
- Java study notes: String (Programming)
- Spring AOP custom annotation way to achieve log management (Programming)
- pkg-config to use (Linux)
- Scala REPL Shell call (Programming)
- Acting on JavaScript events (Programming)
- The basic principles of AIX system security (Linux)
- Install and configure GO 1.2.1 under CentOS 6.5 (Linux)
- Linux program analysis tool: ldd and nm (Linux)
- Build ftp server under CentOS 6.5 (Server)
- secureCRT remote login Linux must first open the connection protocol (Linux)
- Linux `dirname $ 0` (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.