Howdy, ya'll. I have working code that I am trying to make shorter and more concise, as well as more efficient (faster). My code is a little long, but well documented and is located at stu96art's scratchpad .

I also have code that takes the information written from the final.txt file to create a graphical representation of the rectangles. I got this code to work for just one sheet, yet now I have expanded it to create multiple sheets. I need to create multiple sheets of the graphical representation. I am using GD for the graphics and when I was doing only one sheet, I needed only one object, I called im. So when I called my program from the command prompt, I used graphics.pl > im.png. There is no way to use this same system if I am going to have multiple object and multiple representations. Could someone help me with my code. Thanks, and any help is greatly appreciated.
use strict; use warnings; use GD; open ( OH, ">c:/printout1.txt" ) or die ("could not open file. &!" ); open ( GET, "<c:/final.txt" ) or die ("could not open file. &!" ); my ($im, $white, $black, $red, $blue, $green, $purple); my $buf; my (@values, @lines); # create a new image $im = new GD::Image(1000,1000); # allocate some colors $white = $im->colorAllocate(255,255,255); $black = $im->colorAllocate(0,0,0); $red = $im->colorAllocate(255,0,0); $blue = $im->colorAllocate(0,0,255); $green = $im->colorAllocate(0,255,0); $purple = $im->colorAllocate(100,0,175); # make the background transparent and interlaced $im->transparent($white); $im->interlaced('true'); # Put a black frame around the picture #$im->rectangle(0,0,99,99,$black); $im->fill(500,500,$purple); #$im->rectangle(0,0,100,100,$red); #$im->rectangle(100,100,200,200,$red); #$im->rectangle(200,200,300,300,$red); #$im->rectangle(300,300,400,400,$white); my $buffer = <GET>; chomp($buffer); my @big = split /\s+/, $buffer; my $maxx = $big[0]; my $maxy = $big[1]; my $count = 0; my $count2 = 1; my @abet; $abet[0] = "A"; $abet[1] = "A"; $abet[2] = "B"; $abet[3] = "C"; $abet[4] = "D"; $abet[5] = "E"; A:while ($buf = <GET>) { print OH "buf [$buf]\n"; if ($buf =~ /LITE2/) { AA:while ($buf = <GET>) { $count = $count + 1; chomp($buf); print OH "IN LITE2 buf [$buf]\n"; @values = split /\s+/, $buf; if ($buf =~/FINALLY/) { goto B; } print OH "START\n"; print OH "values 0[$values[0]] 1[$values[1]] 2[$values[2]] 3[$va +lues[3]]\n"; if ($values[4] == 0) { $count = 0; $count2 = $count2 + 1; next AA; } # end of if ($values[4] == 0) if ($values[4] == 1) { my $x0 = $values[2]*10; my $y0 = 1000 - ($values[3]*10) - $values[1]*10; my $x1 = ($values[2]*10) + ($values[0]*10); my $y1 = 1000 - ($values[3]*10); my $fx = $x0 + ( ($x1 - $x0) / 2); my $fy = $y0 + ( ($y1 - $y0) / 2); print OH "x0 [$x0] y0 [$y0] x1 [$x1] y1 [$y1]\n"; my $string = "$abet[$count2]-$count"; $im->rectangle($values[2]*10, 1000 - ($values[3]*10) - $value +s[1]*10 , ($values[2]*10)+($values[0]*10), 1000-($values[3]*10), $red + ); $im->string(gdMediumBoldFont,$fx,$fy,$string,$white); } # end of if ($values[4] == 1) } # end of while ($buf = <GET>) OUT: print OH "OUT\n"; } # end of if ($buf =~ /LITE2/) B:if ($buf =~ /FINALLY/) { while ($buf = <GET>) { @lines = split /\s+/, $buf; $im->line($lines[0]*10, 1000-($lines[1]*10), $lines[2]*10, 1000- +($lines[3]*10), $white); } # end of while ($buf = <GET>) } # end of if ($buf =~ /FINALLY/) } # end of while ($buf = <GET>) $im->line(0,1000-($maxy*10),$maxx*10,1000-($maxy*10),$white); $im->line($maxx*10,1000-($maxy*10),$maxx*10,1000,$white); # Put a black frame around the picture #$im->rectangle(0,0,99,99,$black); #$im->fill(50,50,$black); # Draw a blue oval #$im->arc(50,50,95,75,0,360,$green); # And fill it with red #$im->fill(50,50,$purple); # make sure we are writing to a binary stream binmode STDOUT; # Convert the image to PNG and print it on standard output print $im->png;

In reply to Help with efficiency by stu96art

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.