Hi, I have decided to pick up object-oriented perl programming, and I feel fascinated by packages.
Although, when I run the script below, I only get:
Can't locate object method "new" via package "Packet" at /Users/jas/Desktop/oop.pl line 9, <STDIN> line 1.
I can't make out anything of the error message, what is wrong, and what should I do? Thanks in advance!
####
#oop.pl
####
#!/usr/bin/perl -w
package Packet;
use strict;
print "Enter number to be altered:\n";
my $input = <STDIN>;
chomp($input);
my $object = Packet->new($input);
my $result = $object->alter();
print "$result\n";
####
#Packet.pm:
####
package Packet;
use strict;
sub new {
my $new_num = shift;
bless $new_num;
}
sub alter {
my $temp = shift;
$temp += 5;
return $temp;
}
1;
Although, when I run the script below, I only get:
Can't locate object method "new" via package "Packet" at /Users/jas/Desktop/oop.pl line 9, <STDIN> line 1.
I can't make out anything of the error message, what is wrong, and what should I do? Thanks in advance!
####
#oop.pl
####
#!/usr/bin/perl -w
package Packet;
use strict;
print "Enter number to be altered:\n";
my $input = <STDIN>;
chomp($input);
my $object = Packet->new($input);
my $result = $object->alter();
print "$result\n";
####
#Packet.pm:
####
package Packet;
use strict;
sub new {
my $new_num = shift;
bless $new_num;
}
sub alter {
my $temp = shift;
$temp += 5;
return $temp;
}
1;