I haven't looked through the entire code in detail, but in multiple places you're confusing something like

$href->{port_list} # correct

with

$href{port_list} # incorrect - assumes a hash %href

(where the $href stands for $module, $self, etc.)

As the object is a hash reference, you need the arrow here  (you can omit later arrows as in $href->{foo}{bar}, but not the first).

#!/usr/bin/perl -l use strict; # !!! use warnings; my $module = bless { port_list => [qw(a b c)] }, "Foo"; print "size=", scalar @{$module->{port_list}}; # ok print "size=", scalar @{$module{port_list}}; # not ok!

without use strict would give

$ ./835728.pl Name "main::module" used only once: possible typo at ./835728.pl line +9. size=3 Use of uninitialized value $module{"port_list"} in array dereference a +t ./835728.pl line 9. Use of uninitialized value $module{"port_list"} in concatenation (.) o +r string at ./835728.pl line 9. size=

and with:

$ ./835728.pl Global symbol "%module" requires explicit package name at ./835728.pl +line 9. Execution of ./835728.pl aborted due to compilation errors.

Also (though irrelevant to your problem), it's a generally accepted convention to use CamelCase names for normal packages/modules, because all-lowercase names are "reserved" for pragmata (like strict etc.).


In reply to Re: Problem in accessing array of objects. by almut
in thread Problem in accessing array of objects. by sumedhnarayan

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.