Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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?

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
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2022-09-29 09:03 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (125 votes). Check out past polls.