On 9/25/03 7:15 AM, Paul Hoffman <[EMAIL PROTECTED]> wrote:

>> I suppose I could stuff a reference to the @ids array into
>> $self->{term_ids} like this:
>> 
>>   if (@ids) { $self->{term_ids} = [EMAIL PROTECTED] }
> 
> Exactly!
> 
>> But then how do I dereference items in my object?
> 
> sub foo {
>    my ($self) = @_;
>    my $ids = $self->term_ids;
>    # How to dereference a variable that holds an array ref:
>    foreach (@$ids) { ... }
> }
> 
> sub bar {
>    my ($self) = @_;
>    # How to dereference an expression that returns an array ref:
>    my @ids = @{ $self->term_ids };
>    foreach (@ids) { ... }
> }

Thank you very much for the prompt reply. This is what I needed to know, and
this is how I implemented it:


  # use the necessary module
  use MyLibrary::Librarian;
  
  # create a librarian object
  my $librarian = MyLibrary::Librarian->new();
  
  # assign keys (id's) to the librarian object
  $librarian->term_ids(1, 2, 3, 4);
  
  # print each key in $librarian->term_ids
  foreach (@{$librarian->term_ids}) { print "id: $_\n" }
  
  
  sub term_ids {
  
      # get myself and then the ids
      my $self = shift;
      my @ids  = @_;
          
      # check for ids
      if (@ids) { $self->{term_ids} = [EMAIL PROTECTED] }
          
      # return
      return $self->{term_ids};
  
  }


-- 
Eric Morgan
University Libraries of Notre Dame

(574) 631-8604


Reply via email to