- Perl ›
- Object Oriented ›
- Object contents
Play with the created objects
Let's play with the created object.
1. Play with objects
First, let's create a $book object like this. Where it says to play around here, write various things and play.
use strict; use warnings; my $book = Book->new; # # Play around here. # package Book; sub new { my $class = shift; my $self = {}; return bless $self, $class; }
2. Objects are data!
Let's make sure that the object is data .
$book->{title} = 'Good news'; $book->{author} = 'Takeshi';
You can see that you can set the value in the same way as a normal hash reference .
print $book->{title};
Then, the set contents will be output.
3. Objects are tied to a class!
Let's make sure that the object is tied to a class. To see the class association
ref
Use a function.
print ref $book;
Let's try.
Book
You can see that it is output. Yes, you can use the ref function to find out which class the object is associated with.