On Oct 28, Richard Heintze said:

>I have an array stored in an object and I trying to
>compute the length of the array. This seemed to work
>initially:

The LENGTH of an array is @array or @{ $ref_to_array }.  The LAST INDEX of
an array is $#array or $#{ $ref_to_array }.

>my $nColumns = [EMAIL PROTECTED]>{component_titles}}}+1;

You want my $nColumns = $#{ $me->{component_titles} }+1, or even better,
just my $nColumns = @{ $me->{component_titles} }.

>I don't really do anything to create to create this
>array -- I just start storing elements like this:
>
>  $me->{component_titles}[0] = "xyz";
>
>Is there a better way to populate this array? Perhaps
>with a declaration or something?

That's ok.  You can start by saying

  $me->{component_titles} = [];

but that's not necessary.  If you treat an undefined value as an array
reference, it becomes an array reference.  This process is called
autovivification (automatically coming to life).

>my $a = [];
>$me->{a} = \$a;
>$a->[0] = 1;
>$a->[1] = 23;
>
>print $me->{a}->[0];

This is because $a is a reference to an array ALREADY.  Storing \$a in
$me->{a} makes $me->{a} a reference to a reference to an array.  Just
store $a, not \$a.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to