in reply to Re^2: Help with building modules
in thread Help with building modules
Given the use strict that code won't compile, so one presumes that you still have my $msg = shift; etc. That means that those variables are scoped to the new sub and disappear after it returns. You want to store the values off in your instance and then retrieve them from there later.
package Foo; sub new { my $class = shift; my %self = @_; return bless \%self, $class; } sub do_something { my $self = shift; print "msg is: ", $self->{msg}, "\n"; } ## Meanwhile, back on the ranch . . . erm, in the main package package main; my $foo = Foo->new( msg => "WUBBA WUBBA" ); $foo->do-something;
|
|---|