in reply to Re: Learning classes in Perl
in thread Learning classes in Perl

To be frank I don't understand what you said. I am very new to this OOP concept. Please guide to rectify that error. I am taking that example from the  http://perldoc.perl.org/ But still it showing error. I dont understand why?? I am in right side to learn OOP ????

Replies are listed 'Best First'.
Re^3: Learning classes in Perl
by poj (Abbot) on Feb 19, 2016 at 09:38 UTC

    perlobj should explain this for you.

    #!/usr/bin/perl use strict; use warnings; package MyFile; sub new { my ($class,%args) = @_; my $self = { %args }; bless $self,$class; return $self; } sub print_args { my $self = shift; for (sort keys %$self){ print "$_ = $self->{$_}\n"; } } package main; # create new object my $hostname = MyFile->new( path => '/etc/hostname', content => "foo\n", last_mod_time => 1304974868, ); # call method on object $hostname->print_args();
    poj