If you have not already read the numerous tutorials on Perl OO, please do so: perltoot, perlboot, and our own Tutorials.

You have quite a number of problems with your code, i'll attemp to rewrite some of your code, but not all. Try this out:

use strict; use Data::Dumper; my @agents; open (FH,'matrix.csv'); while(<FH>) { chomp; push @agents, VRTSAgent->new(split(/\s*,\s*/,$_,6)); } close FH; print Dumper $_ for @agents; package VRTSAgent; use strict; use Carp; use Data::Dumper; sub new { my $class = shift; my $self = _init(@_); return bless $self, $class; } sub _init { my %init = ( agent => undef, os => [shift,shift], version => [@_], ); return \%init; } # here is how i would code _dump_os # note: if the client is going to call a method # then don't prefix that method with an underscore! # only private methods should be prefixed with underscores sub dump_os { my $self = shift; print Dumper($self->{os}); } # you could call it like so: $_->dump_os for @agents;
I see no reason to store the data file in a transitory array, better to just make the object as you parse the line. So, each line is read and split on a comma with optional surrounding whitespace. The results are passed to the object's constructor, which passes them to it's internal _init() method.

I totally got lazy with the _init() method - this is not good code (see Shift versus Sanity for discussions on why) , but i hope this gives you a new perspective on a hard part of this problem - turning each data piece into an attribute. Good luck, and let us know if you have any other problems in your endeavor.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: When I try to create different objects i end up getting the same one over and over... by jeffa
in thread When I try to create different objects i end up getting the same one over and over... by krujos

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.