Monday, December 24, 2012

Perl 의 loop sample

루프 사용 예:
 #!/usr/bin/perl  
   
 @a = (0, 10, 20, 30, 40, 50);  
 foreach $i (@a)  
 {   
      # $i takes on each list item value in turn  
      printf("%d ", $i);  
 }  
 printf("\n", $i);  
   
 foreach $itm (reverse @a)  
 {   
      # reverse is a functiion that flips the list order  
      print $itm;  
      print " ";  
 }  
 print "\n";  
   
 $i = 0;  
 $item = 0;  
 while($i < 4)  
 {  
      $item = $a[$i];  
      print $item;  
      print " ";  
      $i++;  
 }  
 print "\n";  
   

결과 :
0 10 20 30 40 50
50 40 30 20 10 0
0 10 20 30

 for $i ( 1 .. 10 ) {  
   print($i);  
   print("\n");  
 }  

No comments:

Post a Comment