Expand|Select|Wrap|Line Numbers
- use strict;
- package clTableMaker;
- sub new
- {
- #constructor
- my ($class_name, $width, $border, $cellspacing, $cellpadding) = @_;
- my ($self) = {};
- bless ($self, $class_name);
- my @label = ();
- my @data = ();
- $self->{'_label'} = @label; #assign empty list
- $self->{'_data'} = @data; #assign empty list
- return $self;
- }
- sub add_row
- {
- #add a row of data to the table
- #fill the @label and @data
- push ($self->{'_label'}), $label); #THIS DOES NOT WORK!
- push ($self->('_data'), $data); #THIS DOES NOT WORK!
- }
Expand|Select|Wrap|Line Numbers
- my $table = clTableMaker->new();
- $table->add_row('this is label', 'this is data');
- $table->add_row('this is label2', 'this is data2');
The problem I'm having is that I can't get my head around how to add each row to the properties $self->{'_label'} and $self->{'_data'} using the add_row method. The pushes don't work and I'm assuming this is because I'm trying to push onto a scalar variable.
Can somebody show me how I might achieve this?
Thanks in advance,
Richard