Well, I have played around with this a little bit, and I don't have ALL the answers - this a quite a chunk of code!

I really hope that you are practicing OOP, and not using this in production - no offense, it's not very pretty.

  1. change the initialization of @persons in the Adres constuctor to
    'persons' => ();
    and likewise change all references to @persons to just persons - it's a key, not an array - the value of the key points to an array.

  2. In sub addPerson - you are trying to use Perl arrays like they were C arrays - get rid of your personCount method - you don't need to store the index of the last person added, push will do it for you :)
    # this is all you need to add someone push(@{$self->{persons}},$aPerson);
  3. In printProperties (around line 260) use this:
    my $size = @{$self->{persons}}; for(0..$size) { printf("\t%18.18s => $_\n", "person number"); @{$self->{persons}}[$_]->printProperties(); }
Now you should not be clobbing old users when you add new ones. Disclaimer - I still get a warning that appears to be caused by an empty element in the persons array reference - I'll leave that up to you to fix. :)

Side issues - use CGI and -w

Jeff

R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
L-L--L-L--L-L--L-L--L-L--L-L--L-L--

In reply to (jeffa) Re: Object Inheritance in Perl by jeffa
in thread Object Inheritance in Perl by nims

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.