Re: Passing Argument to a Perl Module Function
[email protected] ("Chas. Owens")
| Newsgroups | perl.beginners |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Jun 4, 2008 at 9:13 PM, KELVIN PHILIP <[email protected]> wrote: snip > my $var = MyModule::PrintMe-> new($name); snip > With this program, when I execute the main, it was not printing "John"; > instead it was printing "MyModule::PrintMe" snip When you call a function with -> the item on the left hand side gets passed as an argument (except when that item is a function reference). This is useful in OO style programming. Since you do not seem to be using OO style you should probably be saying MyModule::PrintMe::new($name); It is also possible that you mean my $obj =MyModule::PrintMe->new("john"); $obj->output; package MyModule::PrintMe; sub new { my ($class, $name) = @_; return bless { name => $name }, $class; } sub output { my $self = shift; print "$self->{name}\n"; } -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read.