You don't show us enough code to be sure what is going wrong, but the following sample may contain the kernel of an "ahh" moment for you:
use warnings;
use strict;
package BankAccount;
sub new {
my ($class, $name, $accountNo) = @_;
return bless {name => $name, accountNo => $accountNo, balance => 0
+}, $class;
}
sub getName {
my ($self) = @_;
return $self->{name};
}
package main;
my $acct = BankAccount->new('Foo', '1234');
print $acct->getName();
Prints:
Foo
There is nothing much different there than you were doing aside from what I consider to be better style. I suspect that you weren't calling the member correctly, but as you don't show that code I can't be sure.
If the "Ahh" moment doesn't arrive for you show your equivalent of the code above.
True laziness is hard work
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.