Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Dear Monks,

I am stumped. What am I doing wrong here.
#!/usr/bin/perl -w use lib ( '../Vector2D' ); use Vector2D; my $POLYGONS_MAX_Y = 11; my $A = new Vector2D( 2, 3 ); my $B = new Vector2D( 7, 1 ); my $C = new Vector2D( 13, 5 ); my $D = new Vector2D( 13, 11 ); my $E = new Vector2D( 7, 7 ); my $F = new Vector2D( 2, 9 ); my @AB = [ $A, $B ]; my @BC = [ $B, $C ]; my @CD = [ $C, $D ]; my @DE = [ $D, $E ]; my @EF = [ $E, $F ]; my @FA = [ $F, $A ]; my @polygon = ( @AB, @BC, @CD, @DE, @EF, @FA ); my @ET; # global Edge Table # each entry in the ET contains the Ymax coordinate of the edge, # the x cooridnate of the bottom endpoint Xbot and the x increment # used in the stepping from one scan lime to the next 1/m for my $edge (@polygon) { my $y = ( @{$edge}->[0]->gety() < @{$edge}->[1]->gety() ) +? @{$edge}->[0]->gety() : @{$edge}->[1]->gety() ; my $Ymax = ( @{$edge}->[0]->gety() >= @{$edge}->[1]->gety() ) +? @{$edge}->[0]->gety() : @{$edge}->[1]->gety() ; my $Xbot = ( @{$edge}->[0]->gety() < @{$edge}->[1]->gety() ) +? @{$edge}->[0]->getx() : @{$edge}->[1]->getx() ; my $invSlope = &calcOneOverSlope($edge); my $rec = { Ymax => $Ymax, Xbot => $Xbot, invSlope => $invSlope }; print "$y -> $Ymax | $Xbot | $invSlope\n"; push( @{$ET[$y]}, $rec ); } for my $i (1..$POLYGONS_MAX_Y) { if ( $ET[$i] ) { print "ET[$i] = "; for my $r ( ${ET[$i]} ) { print "{" . $r->{Ymax} . "|" . $r->{Xbot} . "| +" . $r->{invSlope} . "}" ; } print "\n"; } else { print "ET[$i] = NULL\n"; } } sub calcOneOverSlope { my $edge = shift; my $y = @{$edge}->[0]->gety()-@{$edge}->[1]->gety(); my $x = @{$edge}->[0]->getx()-@{$edge}->[1]->getx(); if ( $y == 0 ) { return undef; } return $x/$y; }
When I execute this I get the following output and error message.
$ ./buildET.pl 
1 -> 3 | 7 | -2.5
1 -> 5 | 7 | 1.5
5 -> 11 | 13 | 0
7 -> 11 | 7 | 1.5
7 -> 9 | 7 | -2.5
3 -> 9 | 2 | 0
Use of uninitialized value in concatenation (.) or string at ./buildET.pl line 49.
Use of uninitialized value in concatenation (.) or string at ./buildET.pl line 49.
Bad index while coercing array into hash at ./buildET.pl line 49.
ET(1] = 
I had hoped that the output would look like this ...
ET(1] = {3 | 7 | -2.5} {5 | 7 | 1.5}
ET(2] = NULL
ET(3] = {9 | 2 | 0}
ET(4] = NULL
ET(5] = {11 | 13 | 0}
ET(6] = NULL
ET(7] = {11 | 7 | 1.5} {7 -> 9 | 7 | -2.5}
ET(8] = NULL
...
ET(20] = NULL
Line 49 is this line ...
  print "{" . $r->{Ymax} . "|" . $r->{Xbot} . "|" . $r->{invSlope} . "}" ;
Thanks

Edited: ~Fri Sep 27 15:05:17 2002 (GMT) by footpad: s/<PRE>/<CODE>/; in last code line, per Consideration.


In reply to Bad index while coercing array into hash by rbc

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (4)
    As of 2014-08-31 02:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (294 votes), past polls