List Info

Thread: easy but stumps me




easy but stumps me
country flaguser name
United States
2008-03-06 17:07:54

I am trying to write a perl program to print out just the summaries of
poker hand histories. These are text files.The problem I seem to have
is that it prints the first summary but won't stop at the end of the
summary but goes on to print out the entire rest of the file.
The patterns are (m/SUMMARY/)to begin and to end (m/ d+ /).
Here's my code:

use strict;
use warnings;
use diagnostics;
my $file="hand.txt";
my array_var;
my $counter=0;
open (FILE,$file) or die "can't open";
while (<FILE&gt; ) {
if(m/SUMMARY/) {

$counter+;+;
print " $counter ";}
if($counter==1){
array_var=$_;
print "array_var&quot;;}
if(m/ d /) {
$counter--; }

}
close FILE;
##############I want to put summaries into an array , one for each hand
############## I can't seem to get it to stop putting stuff into the
array all i want is the summary

__._,_.___
.

__,_._,___
country flaguser name
United States
2008-03-05 18:15:07

Hi MIke,

Try to use elsif

if ($_ =~ /SUMMARY ) {bla; }
elsif ($counter==0) {bla; }
elsif ($_ =~ /d+) { bla; last; }

with last it should jump out of the loop

On Mar 6, 2008, at 6:07 PM, mike97739 wrote:

> I am trying to write a perl program to print out just the summaries of
> poker hand histories. These are text files.The problem I seem to have
>; is that it prints the first summary but won't stop at the end of the
> summary but goes on to print out the entire rest of the file.
&gt; The patterns are (m/SUMMARY/)to begin and to end (m/ d+ /).
> Here's my code:
&gt;
> use strict;
> use warnings;
> use diagnostics;
> my $file=&quot;hand.txt";
&gt; my array_var;
> my $counter=0;
> open (FILE,$file) or die "can't open";
> while (<FILE&gt; ) {
> if(m/SUMMARY/) {
>
> $counter&#43;+;
>; print " $counter ";}
> if($counter==1){
&gt; array_var=$_;
>; print "array_var&quot;;}
> if(m/ d /) {
> $counter--; }
>
> }
> close FILE;
&gt; ##############I want to put summaries into an array , one for each
> hand
>; ############## I can't seem to get it to stop putting stuff into the
> array all i want is the summary
>
>
>

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )