Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Array in Object Question

Reply
Thread Tools

Array in Object Question

 
 
afrinspray
Guest
Posts: n/a
 
      08-17-2005
I have a quick question about accessing an array reference from an
object hash.

Say I have an object $obj and it has an array reference that can be
accessed like this:

@{$obj->array}

Does $#{$obj->array} return the length? If not, does @{obj->array} (if
used in the right context)?

Also how would I scroll through each element in the array and change
it's contents (they are string and I want to append something to each
string).

Thanks in advance,
Mike

 
Reply With Quote
 
 
 
 
roberto0
Guest
Posts: n/a
 
      08-17-2005
Hey Mike,

let me get your meaning correctly:

$obj is the object
$obj->array is the array reference

If this is the case, then
$#{obj->array}
should return the index of the last element in the array.

(@{$obj->array})
will evaluate to the size of the array.
$obj->array->[$i] is the $ith element of the array and can be
incremented to parse/change/etc.

cheers,
Rob Anderson

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
Length of Array of Array of Array Tom Perl Misc 3 12-20-2004 05:23 PM
Passing derived class object array in place of base class object array justanotherguy63@yahoo.com C++ 9 12-03-2004 10:57 PM
Problem assigning an Array object to an Array-subclass object Richard Lionheart Ruby 27 05-04-2004 06:42 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57