Array in Object Question

Discussion in 'Perl Misc' started by afrinspray, Aug 17, 2005.

  1. afrinspray

    afrinspray Guest

    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
     
    afrinspray, Aug 17, 2005
    #1
    1. Advertising

  2. afrinspray

    roberto0 Guest

    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
     
    roberto0, Aug 17, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    9
    Views:
    597
    justanotherguy
    Dec 3, 2004
  2. Mara Guida

    const and array of array (of array ...)

    Mara Guida, Sep 2, 2009, in forum: C Programming
    Replies:
    3
    Views:
    525
    David RF
    Sep 3, 2009
  3. Richard Lionheart
    Replies:
    27
    Views:
    441
    Jean-Hugues ROBERT
    May 4, 2004
  4. Tom
    Replies:
    3
    Views:
    237
    salsablr
    Dec 20, 2004
  5. Tuan  Bui
    Replies:
    14
    Views:
    532
    it_says_BALLS_on_your forehead
    Jul 29, 2005
Loading...

Share This Page