On 8/9/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi,
>
> In the following example I have to print all the line from line "FROM" till 
> "END" not including the "FROM" line and the "END" line.
> That is if the file consists from the following lines:
>
> ds
> FROM
> 1
> 2
> 3
> 34
> 5
> 6
> END
> dsa
>
> I would like to print:
> 1
> 2
> 3
> 34
> 5
> 6
>
> I would like to accomplish that with range operator. But the following script 
> will add the FROM ann the END line to the output.
> Is there an efficient way to do that.
> In other words I would like to have range operator that will return true for 
> all the line inside the range not including the first and last line.
>
>
> BFN
>
>
> Yaron Kahanovitch
>
>
>
>  #!/usr/bin/perl
>
> while (<DATA>) {
>   print $_ if ( /FROM/ .. /END/ );
> }
>
> __END__
> ds
> FROM
> 1
> 2
> 3
> 34
> 5
> 6
> END
> dsa
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>

This mostly works, but doesn't do the right thing for START inside the range

#!/usr/bin/perl -n

print if /START/ .. /END/ and not (/START/ or /END/)

This works, but doesn't use the filpflop* operator

#!/usr/bin/perl

my $in = 0;
while (<>) {
    $in = 0 if /END/;
    print if $in;
    $in = 1 if /START/;
}

In Perl 6 the range and flipflop operators are being separated into ..
and ff respectively.  Both will have the ability to exclude the
extreme item on either side using ^.  So, in Perl 6 your code would
look something like this

#!/usr/bin/perl

use v6-alpha;

for =<> {
    print if /START/ ^ff^ /END/;
}

* in scalar context .. is the flipflop operator, in list context .. is
the range operator
** or at least this is how I read S03

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


Reply via email to