Hi Eric: On Mon, Nov 01, 2004 at 10:40:36PM -0500, Eric Lease Morgan wrote: > In a package I'm writing I initialize an array reference (I think) > through DBI like this: > > $self->{author_ids} = $dbh->selectall_arrayref($query); > > First of all, what sort of foreach loop can I write to iterate through > the contents of $self->{author_ids}?
De-reference the array reference, here's one example: foreach my $id ( @{ $self->{author_ids} } ) { ... } > Second, how do I undefine the value of $self->{author_ids}? $self->{author_ids} = undef; But if I were you I'd have your constructor initialize the slots that can contain array references to an empty array reference: sub new { my $class = shift; my $self = bless {}, $class; $self->{author_ids} = []; } The advantage here is that you won't attempt to use undef as an array reference somewhere in your code. This is a runtime error in Perl, so it can result in an unpredictable program if the code isn't exercised all the time. > Third, if I have a list of integers, how to I assign the items in this > list to $self->{author_ids}? $self->{author_ids} = [ @list_of_integers ]; or if you don't mind the list being referenced from two locations: $self->{author_ids} = [EMAIL PROTECTED]; Hope this helps! //Ed -- Ed Summers aim: inkdroid web: http://www.inkdroid.org The deeper I go the darker it gets. [Peter Gabriel]