Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Introductory Question regarding Perl Objects

Status
Not open for further replies.

patstarks

Technical User
Oct 4, 2009
3
US
Hello,
I am just learning perl objects and I am having some trouble fully grasping the concept. So I made a simple example to figure it out however it is not working.
I created two files: object_tut.pl and Person.pm

In this simple example I have a string $seq which I turn into an object via a sub located in Person.pm called create. This sub turns $seq into an object. I then concatenate the string $seq into itself using a method located in Person.pm. However, when I print my strings I am getting some unexpected results about Person=HASH....

#############################
Here is object_tut.pl:
#############################
#!/usr/bin/perl
use warnings;
use strict;
use lib 'C:\begperl\Lessons\L5_Objects';
use Person;

my $seq = "AGCTGTGACGA";
print "Here is the string before create call " , ref($seq) , " $seq\n";
$seq = Person->create($seq);
print "Here is the string after create call " , ref($seq) , " $seq\n";
my $added = Person->concatenate($seq);
print "$seq\n";
print "$added\n";
exit(0);

#######################################
Here are the contents of Person.pm
#######################################
#!/usr/bin/perl
package Person;
use warnings;
use strict;

sub create{
my $class = shift;
my $self ={};
bless($self, $class);
return $self;
};

sub concatenate{
my $string = shift;
my $ret_string = $string . $string;
return $ret_string;
}

1;

##################################
Here is the output
##################################
Here is the string before create call AGCTGTGACGA
Here is the string after create call Person Person=HASH(0x6faf14)
Person=HASH(0x6faf14)
PersonPerson
################################
How come it does not return the string concatenated to itself? Is there something I am missing?

Thanks,
Starks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top