Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

The .. operator explained

by Cine (Friar)
on Aug 05, 2003 at 17:49 UTC ( #281102=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    for (1 .. 100) {
      # Do something with $_, which will start with the value 1,
      # increasing by one for every loop and stopping with the value 100.
    }
    
  2. or download this
    for ('a' .. 'z') {
      # $_ will start with the value 'a', then 'b' all the way up to 'z'
    ...
      # $_ will start with the value 'aa', then 'ab', then 'ac' up to
      # 'az', then 'ba' and finally 'bb'
    }
    
  3. or download this
    while(<>) {
      print if 1 .. 5; #Print lines 1 trough 5 including.
    }
    
  4. or download this
    while(<EMAIL>) {
      my $body = /^$/ .. eof; #First blank line in email is start of body
    ...
      print "looking at line ",int$body," in the body\n" if $body;
      print "looking at line ",int$header," in the header\n" if $header;
    }
    
  5. or download this
    while(<>) {
      my $line = /\S/ ... /^$/;
      print "$line:$_" if $line && $line!~/E0$/;
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://281102]
Approved by dragonchild
Front-paged by dragonchild
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2014-09-18 13:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (115 votes), past polls