Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For and If issues

Status
Not open for further replies.

vadg

Technical User
Joined
Mar 4, 2007
Messages
9
Been trying to figure this out and have had no luck with other forums.

here's the code:

Code:
use GD::Graph::linespoints;


my $data_file = "ChartdataMYBUG.txt";

open DATA, "$data_file" or die "can't open $data_file $!";
 undef $/;
 $_ = <DATA>;
  close DATA;
$/ = "\n"; 

my @data = ([1,2,3], [3,4,5], [6,7,8]);    ### just a valid array for the print call so the program will execute
for my $r (0 .. 1) {

	if (/comments(.*?)quotes/sg) {
		$all=$1;
		print "all is $all\n";
			
}
my $g = GD::Graph::linespoints->new(100,100);  ##graph starts here
  

  $g->set( 
      x_label           => 'X Label',
      y_label           => 'Y label',
      title             => 'Some simple graph',
      y_max_value       => 8,
      y_tick_number     => 8,
      y_label_skip      => 2
  ) or die $g->error;	
  
  my $format = $g->export_format;
  open (IMG, ">BLOT$r.$format") or die $!;
  binmode IMG;
 
  print IMG $g->plot(\@data)->$format();

  close IMG;                              ##graph ends here
	
}
here's the file:

Start

comments

1 1 1
2 2 2
3 3 3
4 4 4

quotes

End

Start

comments

5 5 5
6 6 6
7 7 7
8 8 8

quotes

End


Disregard what's happening in the graph code.
The issue is that if I include the chart portion within FOR and/or IF I only get the first part of the data match (111, 222, 333, 444) TWICE. So it does iterate (apparently).

If I place the graph code outside the for/if

I get the entire data (first match 1st time through; second match 2nd time through).

I've written a sizable program that depends on printing graphs at the end of each cycle. If I can't solve this I'll have to rewrite the code.

Thanks
 
How about something like this...
Code:
if (/comments(.*?)quotes/sg) {
   $all=$1;
   [red]$_ = $';[/red]
   print "all is $all\n";
}
So the next search will have to start where the last one left off.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top