PERL OOP newbie question: What is the best way to handle array data?



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;

###############

.



Relevant Pages

  • Re: VB-101: Passing Arrays ByVal vs ByRef
    ... changed if an array is passed by Val. ... ' new reference ... As each function creates a new array object, ... 'secondArray' and 'secondArrayCopy'. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Need help with textboxes
    ... The JavaScript 1.5 Reference already states: ... All forms and their children are stored in an array ... use dot notation or object literals. ... No. Bracket property accessors allow their argument to be any string value. ...
    (comp.lang.javascript)
  • Re: Garbage Collection Issues in long-standing services
    ... the pinned array should get unpinned or ... The receive case is done quite well, I do create a 4K buffer and reuse it ... and remove the reference to my wrapper socket class, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to give selective access to the methods in a class?
    ... different memory locations at different times. ... The reference still leads to the ... So array resizing ... program pushes certain objects into the circular buffer, ...
    (comp.lang.java.programmer)
  • Re: Perlish map() function
    ... the reference material, the Array constructor was introduced in JavaScript ... evaluation would result in a ReferenceError. ... identifier shows that it is true. ...
    (comp.lang.javascript)