PERL OOP newbie question: What is the best way to handle array data?
- From: lovellj@xxxxxxxxxxx
- Date: 30 Apr 2007 23:22:51 -0700
Hi,
The only way I could get arrays to work with OOP in perl was to use a
reference to an array. I am wondering is this safe - ie is there any
chance that some part of the array may get overwritten in memory since
I am just using the reference in the functions? What is the best way
to do this?
I tried assigning $self->{'data_array'} = ("MON","TUE","WED"), but
then I found when I try to access this data, the array gets messed up
and it comes out as a scalar or as the last value in the array.
I apologize in advance if there is an obvious way to do this. Thanks
so much,
Jon
#####Test_class.pm
#!/usr/bin/perl -w
package Test_class;
use strict;
sub new
{
my $class = shift;
my $self = {};
my @arr = ("MON","TUE","WED");
$self->{'data_array'} = \@arr;
bless ($self,$class);
return $self;
}
sub function1
{
my $self = shift;
my @data_array = @{ $self->{'data_array'} };
###use the data...
###..... Is this safe - is there any chance parts of the array will
be deleted in memory
}
1;
###############
.
- Follow-Ups:
- Re: PERL OOP newbie question: What is the best way to handle array data?
- From: Joe Smith
- Re: PERL OOP newbie question: What is the best way to handle array data?
- From: Martien verbruggen
- Re: PERL OOP newbie question: What is the best way to handle array data?
- Prev by Date: Re: FAQ 4.51 How do I permute N elements of a list?
- Next by Date: FAQ 4.37 What's wrong with always quoting "$vars"?
- Previous by thread: FAQ 4.46 How do I handle linked lists?
- Next by thread: Re: PERL OOP newbie question: What is the best way to handle array data?
- Index(es):
Relevant Pages
|