N
Nene
This is my first attempt to OOP, here is my package:
#####
package Learn;
use strict;
sub new {
my $class = shift;
my $learn_oop = {};
return bless $learn_oop, $class;
}
sub set_farm {
my $learn_oop = shift;
my $farm = shift;
$learn_oop->{farm} = $farm;
}
sub get_farm {
my $learn_oop = shift;
return $learn_oop->{farm};
}
sub set_port {
my $learn_oop = shift;
my $port = shift;
$learn_oop->{port} = $port;
}
sub get_port {
my $learn_oop = shift;
return $learn_oop->{port};
}
sub print_variables {
print "Do something with $learn_oop->{farm} and with $learn_oop-
#####################
This is my perl script
#!/usr/bin/perl -w
use strict;
use Learn;
my $farm = "WEB";
my $port = "1234";
my $status = "enabled";
my $test = Learn->new();
$test->set_farm($farm);
$test->set_port($port);
$test->print_varibles();
exit 0;
#######
My print_variables() method is not working, I get:
root@rsimioni-desktop:/home/control/perlstuff# ./quote.pl
Global symbol "$learn_oop" requires explicit package name at /usr/lib/
perl/5.10/Learn.pm line 36.
Global symbol "$learn_oop" requires explicit package name at /usr/lib/
perl/5.10/Learn.pm line 36.
Could somebody point me in the correct directions, thanks in
advance...
#####
package Learn;
use strict;
sub new {
my $class = shift;
my $learn_oop = {};
return bless $learn_oop, $class;
}
sub set_farm {
my $learn_oop = shift;
my $farm = shift;
$learn_oop->{farm} = $farm;
}
sub get_farm {
my $learn_oop = shift;
return $learn_oop->{farm};
}
sub set_port {
my $learn_oop = shift;
my $port = shift;
$learn_oop->{port} = $port;
}
sub get_port {
my $learn_oop = shift;
return $learn_oop->{port};
}
sub print_variables {
print "Do something with $learn_oop->{farm} and with $learn_oop-
}{port}";
#####################
This is my perl script
#!/usr/bin/perl -w
use strict;
use Learn;
my $farm = "WEB";
my $port = "1234";
my $status = "enabled";
my $test = Learn->new();
$test->set_farm($farm);
$test->set_port($port);
$test->print_varibles();
exit 0;
#######
My print_variables() method is not working, I get:
root@rsimioni-desktop:/home/control/perlstuff# ./quote.pl
Global symbol "$learn_oop" requires explicit package name at /usr/lib/
perl/5.10/Learn.pm line 36.
Global symbol "$learn_oop" requires explicit package name at /usr/lib/
perl/5.10/Learn.pm line 36.
Could somebody point me in the correct directions, thanks in
advance...