Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

The .. operator explained

by Cine (Friar)
on Aug 05, 2003 at 17:49 UTC ( [id://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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-03-28 10:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found