Skip to main content
Hide Sidebar
Show Sidebar
<Progzoo Sections>
ProgZoo
Tutorials
How to...
Assessments
Help
<Other>
To do list
Recent changes
Random page
Personal
Log in / create account
Views
Perl
Discussion
View source
History
Toolbox
What links here
Related changes
Special pages
Printable version
Tutorials
SET07102
Guides
Log in
Java
C#
C++
Perl
PHP
Python
Ruby
VB
Perl:Define a Class
From Progzoo
Perl:Top Ten Tips
Hello World
Convert to Number
Read Text File
Sum an Array
Count 0 to 9
Hash Table
Regular Expression
Read Database
Read XML
Define a Class
The class Person has
an initialisation:
new
attributes
name, weight
and
height
a method:
bmi
.
{ package Person; sub new { my ($class,$name,$weight,$height) = @_; my $self = { name => $name, weight => $weight, height => $height }; bless ($self, $class); return $self; } sub bmi { my ($self) = @_; return $self->{weight}/$self->{height}/$self->{height}; } } my $p = Person->new("andrew",99,1.8); print $p->bmi, "\n"; print $p->{name}, "\n";
[
Font
] [
Default
] [
Show
] [
Resize
] [
History
] [
Profile
]
test text