From: "sudhindra k s" <[EMAIL PROTECTED]>
> Can someone please tell me what the following code is trying to do 
> 
>       if ( /CR List/ .. /\(2\)/ ) {
>          if ( /CR List/ )  { print " $'\n"; }
>          elsif ( /\(2\)/ ) {print " $` \n" ;}
>          else              { print "            $_\n";}
>         }
> 
> I know that it is trying to print whatever is there between CR List
> and (2). But i am not able guess more than that. 

The magic is in the .. operator. It returns false until the first 
operand evaluates to true, then it returns true until after the  
second operand evaluates to true, then again false until the first 
becomes true ...

Let me give you a simpler example:

foreach my $var (1,2,3,4,5,6,7,8,9) {
        if ($var == 3 .. $var == 6) {
                print "$var\n";
        }
}


The operator works like the following code:

my $_status = 1;
foreach my $var (1,2,3,4,5,6,7,8,9) {
        if ($_status == 1) {
                if ($var == 3) {
                        $_status = 2;
                        print "$var\n";
                }
        } else {
                print "$var\n";
                if ($var == 6) {
                        $_status = 1;
                }
        }
}

HTH, Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to