Objects instead of global variables in Perl
- by Gaurav Dadhania
I don't know if this is the right thing to do. But I'm lookig for tutorials/articles on using objects instead of global variables to store state. For eg.
package something
# some code here...
# that generates errors and uses
# something::errors to track errors.
package something::errors
sub new {
my ($this) = @_;
bless $this;
return $this;
}
sub setErrors{
my ($this, @errors) = @_;
$this->{errors} = \@errors;
}
sub getErrors{
my ($this) = @_;
return $this->{errors};
}
Is this better than using global varibles? Any down-sides to this? Any approach which might be better?
Thanks.