On 3/14/12 Wed  Mar 14, 2012  8:15 AM, "lina" <lina.lastn...@gmail.com>
scribbled:

>> 
>> Use the range operator to delimit the section you want to extract.
>> You can read about in 'perldoc perlop'
>> 
>> if ($line =~ /^A$/ .. $line =~ /^C$/) {
> 
> Hi,
> 
> I came back to this again, last time tried to match all under A, like
> 
> A
> 1 1
> 3 1
> B
> 1 3
> 1 5
> A
> 1 1
> 
> Here what if I wish it only meet once A and stoped at B, how can I
> quit like /B/q;/A/p
> the result is
> A
> 1 1
> 3 1

As has been suggested before, you can use a flag to keep track of whether or
not you are printing lines. Then, you can exit the loop upon the first
occurence of B:

my $print;
while(<DATA>) {
  last if /B/;
  $print = 1 if /A/;
  print if $print;
}


-- 
Jim Gibson



-- 
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