Perllace has asked for the wisdom of the Perl Monks concerning the following question:
sub new { my ($class,$device,$serveraddr,$port) = @_; my $self = {}; bless ($self,$class); $self = { 'device' => $device, 'serveraddr' => $serveraddr, 'port' => $port };
THe same module, needs to take care of creating an object of another package, for this I need to pass the values of serveraddr and port, how do I do that ?
for ex, (I know this is wrong,I get Global Symbol $self,$serveraddr,$port requires explicit package name error)Communication.pm inturn containsmy $SockObj = Communication->new( $self->{$serveraddr}, $self->{$port} +);
Any advice would be very helpful. Thanks, Perllacesub Communication::new { my $class = shift; my ($addr, $port) = @_; my $socket = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $addr, PeerPort => $port, ) or die "couldn't connect: $!"; $socket->autoflush(); return bless $socket, $class; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to send attributes of an object to create an object of another class?
by wfsp (Abbot) on Apr 06, 2011 at 11:16 UTC | |
|
Re: How to send attributes of an object to create an object of another class?
by chromatic (Archbishop) on Apr 06, 2011 at 23:19 UTC | |
|
Re: How to send attributes of an object to create an object of another class?
by Anonymous Monk on Apr 06, 2011 at 10:11 UTC |