Thank you everyone for you help.

-Chris


On Sat, Feb 9, 2013 at 5:15 PM, Uri Guttman <u...@stemsystems.com> wrote:

> On 02/09/2013 03:59 PM, John W. Krahn wrote:
>
>
>> Let's re-factor that down to its essence:
>>
>> while ( <DATA> ) {
>>      print if /\|68\|/;
>>      print "$1\t$2\t$3\n" if /(\|\d)\|(\d+)\|(\d+)/;
>>      }
>>
>> Now we need to add something that starts at |68| and stops at #END:
>>
>> while ( <DATA> ) {
>>      if ( /\|68\|/ .. /^#END/ ) {
>>          print if /\|68\|/;
>>          print "$1\t$2\t$3\n" if /(\|\d)\|(\d+)\|(\d+)/;
>>          }
>>      }
>>
>
> there is a great feature with the .. flip/flop op that isn't well known.
> it returns not just a boolean state but a count of where it is in the
> range. so you can use that value to handle the first line differently and
> not need to copy the regex which can lead to a bug if it changes and you
> forget to edit both copies:
>
>         if ( my $range = /\|68\|/ .. /^#END/ ) {
>                 print if $range == 1 ;
>
> the last line in the range gets a number with E0 appended so it is the
> same value but you can check for the /E/ and do something there:
>
>                 print "DONE\n" if $range =~ /E/ ;
>
> uri
>
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

Reply via email to