Object Oriented Perl
If your focus is on learning Object-Oriented Perl, not on learning Pogo, I suggest you just follow one of perl's built-in tutorials by running the command: perldoc perltoot
. This would quickly lead you to the following solution:
file Person.pm
package Person;
use strict;
sub new {
my $self = {};
$self->{NAME} = undef;
$self->{AGE} = undef;
bless $self;
return $self;
}
sub varName {
my $self = shift;
if (@_) { $self->{NAME} = shift; }
return $self->{NAME}
}
sub varAge {
my $self = shift;
if (@_) { $self->{AGE} = shift; }
return $self->{AGE}
}
1;
file person.pl
#!/usr/bin/perl
use strict;
use warnings;
use Person;
my $p = Person->new();
$p->varName('Anna');
$p->varAge(30);
print $p->varName." is ".$p->varAge." years old.\n";
Running it:
$ perl person.pl
Anna is 30 years old.
Perl Modules
You asked
how to install the Person module
You seem to be installing a module named Pogo not
one named "Person".
why I get the following:
...
/bin/sh: g++: command not found
It seems you don't have a full development kit installed. Have you checked the documentation for your Linux distribution? Each different distribution has their own package manager you can use to install a development kit.
You can try to use the cpan
command but I expect you might have the same problem.
RHEL Development Tools
In order to install perl modules that are not "pure perl" you will need a C or C++ compiler and some other tools and libraries. What follows is extracted from a Slicehost article that I believe applies to RHEL 5.4 generically (I use CentOS, so I have no direct experience of installing RHEL packages)
Package repositories
RHEL comes with a basic set of repositories.
Have a look at the enabled repositories by running:
sudo yum repolist enabled
Each repository listed should include a brief description and the number of packages available
from that source.
If you'd like to have a look at the configuration files that point to each repository, they're
stored in this directory:
/etc/yum.repos.d
If you look through one of the files there, you will see each repository has a set of
definitions including which mirror to use and what gpg key to use (and actually whether to
check the package signature at all).
You can, of course, add more repositories whenever you want to but I would just give a word of
caution: Some of the available repositories are not officially supported and may not receive
any security updates should a flaw be discovered.
Update
Now we can update the package list that yum uses.
The following command will also offer to install any updated packages. As with all installs
have a careful look at the list and, once happy, press 'y' to continue:
sudo yum update
Once any updates have been installed, we can move on to installing some essential packages.
Development Tools
RHEL has some handy meta-packages that include sets of pre-defined programs required for a
single purpose.
So instead of installing a dozen different package names, you can install just one meta-
package. One such package is called 'Development Tools'. Issue the command:
sudo yum groupinstall 'Development Tools'
Notice the programs that are to be installed include gcc, make, patch and so on. All these are
needed for many other programs to install properly. A neat system indeed.
Enter 'y' and install them.
Now we have the necessary packages should we want to build an application from source.
Done
CentOS
If you have not paid for a RHEL subscription and registered it, I suspect you might not have access to RedHat package repositories. You would therefore be unable to install packages such as the development tools. There are ways to work around this but the sensible course of action is to install CentOS instead - it is almost exactly like RedHat (omitting RedHat trademarks and copyrighted images etc) but has working repositories that can be used without paying a subscription fee.
@RedGrittyBrick hi where I can find the "full development kit" ? – yael – 2011-02-09T10:58:17.967
@yael, what Linux distribution and version are you using? Ubuntu 10.10 Desktop? If so
sudo aptitude update && sudo aptitude install g++
– RedGrittyBrick – 2011-02-09T11:27:46.370my linux - Red Hat OS release.5.4 – yael – 2011-02-09T11:33:35.050
@Yael: For RHEL 5.4
yum groupinstall "Development Tools"
You may also needyum groupinstall "Development Libraries"
. – RedGrittyBrick – 2011-02-09T11:37:22.860but I get - yum groupinstall "Development Tools" Loaded plugins: security Setting up Group Process Warning: Group Development Tools does not exist. No packages in any requested group available to install or update – yael – 2011-02-09T11:54:58.200
@Yael: What is the response to
– RedGrittyBrick – 2011-02-09T13:35:21.467yum grouplist
. Is your RedHat subscription up to date and registered? If you don't have a RedHat subscription you should be able to use the CentOS repositories but in that case it is probably best to have installed CentOS not RHEL in the first place.@RedGrittyBrick the response like this: [root@linux /tmp]# yum grouplist Loaded plugins: security Setting up Group Process Error: No group data available for configured repositories – yael – 2011-02-10T03:49:26.343
@Yael: Is your RedHat subscription paid? – RedGrittyBrick – 2011-02-10T09:14:02.883
I have edited the question's title and added some tags. I have updated my answer to cover some of the material discussed in the comments above. – RedGrittyBrick – 2011-02-10T10:11:18.190