APM: OO Perl Question
Bill Raty
bill_raty at yahoo.com
Fri Jun 28 00:02:03 CDT 2002
Sorry!! Got in a fight with my mouse!
Another way to get a reference to a list is via the
anonymous listref maker, brackets:
# makes reference to copy of list
my $listref = [ @Object::LIST ];
Don't misunderestimate the power of having a copy, esp. if you
don't want to have your original list accidentally overwritten;
references can allow a user of your library to wipe out your
quasi-constant list (I know, Java paranoia).
And the way to dereference a listref:
my @list = @{$object->{LIST}}; # if LIST is a listref
Since I may not be understanding what you're doing (and I've
been doing -way- too
much Java lately), here's another example:
my $anon_list_ref = [ "a", "b", "c" ];
my @copy_of_list_ref = @$anon_list_ref;
# Stuff thing into a "$self" hash
my $self = {};
$self->{LIST} = [ qw(a b c) ];
# Deref LIST member of $self
my @list = @{$self->{LIST}};
Enjoy!,
-Bill
--- David Bluestein II <dbii at mudpuddle.com> wrote:
> Okay, I've been coding too much this week and I've got an OO
> Perl question
> as I'm trying to expand my horizons (now that I kind of
> understand $self
> :).
>
> In my object, I want a list, @Object::LIST, which does not
> change during
> runtime (it contains a list of fields in a database). In my
> main program, I
> create an OBJECT:
>
> my $id = $q->param('id');
>
> # create object
> my $object = new Object( ID => $id );
> # create reference to the list of fields
> my $listref = \@Object::LIST;
>
> I want to make this simpler though, and not involve the
> @Object::variable
> syntax.
>
> Questions are:
> 1) How do I define an @LIST in my Object.pm, and how do I
> construct the
> syntax to access it in my main program, such that I can
> change the above
> code to:
>
> my $id = $q->param('id');
>
> # create object
> my $object = new Object( ID => $id );
> # Set the variable @list equal to the @LIST in the $object.
> Syntax is wrong
> here (I tried it)
> my @list = $object->@LIST;
>
>
> Thanks-
>
> David
>
>
>
> ----------
> David H. Bluestein II President &
> Lead Developer
> dbii at mudpuddle.com ii, inc.
>
> http://www.interaction.net
> - Specializing in Designing Interactive Websites
> -
> - and Searchable Internet Databases
> -
>
>
>
>
>
> _______________________________________________
> Austin mailing list
> Austin at mail.pm.org
> http://mail.pm.org/mailman/listinfo/austin
=====
Anon: "We'll be done by the schedule date, maybe later."
__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com
More information about the Austin
mailing list