Fellow monks, please consider this code:
2 use strict; 3 use GD; 4 5 my $length = 2; #number of repeats 6 my $image = new GD::Image($length*37+1,13); 7 my $white = $image->colorAllocate(200,200,200); 8 #$image->transparent($white); 9 my $yellow = $image->colorAllocate(255,255,0); 10 my $black = $image->colorAllocate(0,0,0); 11 my ($x, @para1, @para2); 12 13 while ($x <= $length-1){ 14 $para1[$x] = new GD::Polygon; 15 $para1[$x]->addPt(0+$x*12,0); 16 $para1[$x]->addPt(12+$x*12,12); 17 $para1[$x]->addPt(24+$x*12,12); 18 $para1[$x]->addPt(12+$x*12,0); 19 20 $para2[$x] = new GD::Polygon; 21 $para2[$x]->addPt(13+$x*12,0); 22 $para2[$x]->addPt(25+$x*12,12); 23 $para2[$x]->addPt(37+$x*12,12); 24 $para2[$x]->addPt(25+$x*12,0); 25 26 $x++; 27 } 28 29 while ($x >= 0){ 30 $image->filledPolygon($para1[$x], $black); 31 $image->filledPolygon($para2[$x], $yellow); 32 33 $x--; 34 } 35 print $image->png();

I'm am receiving this error Can't call method "length" on an undefined value at line 30

Can anyone offer some advice as to the cause? Neil Watson
watson-wilson.ca


In reply to GD, arrays, and Polygons by neilwatson

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.