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 ( [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 romping around the Monastery: (4)
As of 2024-03-28 16:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found