Hi I have a small piece of code similar to the one below:
#!/usr/bin/perl package main; use strict; use warnings; my $obj = test2->new(); $obj->get_name; $obj->get_namer; package test2; sub new { my $class = shift; my $self = { lib => undef}; bless($self,$class); my $lib = test1->new(); ($self->{lib}) = ($lib->print_name()); return $self; } sub get_name { my $self = shift; return $self->{lib}->print_name(); } sub get_namer { my $self = shift; return $self->{lib}->print_namer(); } package test1; sub new { my $class = shift; my $self = {}; bless($self,$class); return $self; } sub print_name { my $self = shift; print "From test1","\n"; } sub print_namer { my $self = shift; print "Here is another namer","\n"; }

The above code is saved into a file called 'll.pl'. When I execute the above code as './ll.pl', I get the following message
From test1 Can't call method "print_name" without a package or object reference a +t ./ll.pl line 27.

can you please help me understand what I am doing wrong?

Best Regards,
Dayle Kotturi.

In reply to Need help with OO perl by dkotturi

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.