Length of Array of Array of Array

Discussion in 'Perl Misc' started by Tom, Nov 23, 2004.

  1. Tom

    Tom Guest

    How to find the length of an "Array of Array of Array"

    I get syntax error when i say $#fx[0][0][0]
     
    Tom, Nov 23, 2004
    #1
    1. Advertising

  2. Tom

    Matija Papec Guest

    X-Ftn-To: Tom

    (Tom) wrote:
    >How to find the length of an "Array of Array of Array"
    >
    >I get syntax error when i say $#fx[0][0][0]


    This should give you the latest index from third level array,
    $#{ $fx[0][0] }



    --
    Matija
     
    Matija Papec, Nov 23, 2004
    #2
    1. Advertising

  3. Tom <> wrote:

    > How to find the length of an "Array of Array of Array"
    >
    > I get syntax error when i say $#fx[0][0][0]



    Well first off, the $#array syntax does NOT give you the length
    of the array, it gives you the last index in the array.

    The @array syntax in a scalar context gives you the length of the array.


    To find the length of your multi-dim array, simply apply "Use Rule 1" from:

    perldoc perlreftut


    I usually do it in 3 steps:

    my $length = @array; # pretend it is a regular old array

    my $length = @{ }; # replace the _name_ of the array with a block

    my $length = @{ $fx[0][0][0] }; # fill in the block with code that
    # returns a reference to the
    # right kind of thingy

    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Nov 23, 2004
    #3
  4. Tom

    salsablr Guest

    Thanks for the Info, I figured out and its working

    $# {$g_Ao_TEList[$index]{$teIt}[0][0]} yields the last index of the
    array.


    salsablr wrote:
    > Well, I'm yet to figure out what is causing the problem.
    > My data structure is a little complex (atleast complex for me)
    >
    > $# {$g_Ao_TEList[$index]{$teIt}[0][0]}
    > <=== This doesn't works; infact i tried to store the count in
    > $lines which results nothing.
    >
    > I have an "Array(1)" which references to "Array of Hashes" and the
    > value of each of the keys in the array references to an "Array of

    Array
    > of Array"
    >
    > Now 'm trying to get the last index of the Array from "Array of Array
    > of Array".... Any pointers..
    >
    >
    > Tad McClellan wrote:
    > > Tom <> wrote:
    > >
    > > > How to find the length of an "Array of Array of Array"
    > > >
    > > > I get syntax error when i say $#fx[0][0][0]

    > >
    > >
    > > Well first off, the $#array syntax does NOT give you the length
    > > of the array, it gives you the last index in the array.
    > >
    > > The @array syntax in a scalar context gives you the length of the

    > array.
    > >
    > >
    > > To find the length of your multi-dim array, simply apply "Use Rule

    1"
    > from:
    > >
    > > perldoc perlreftut
    > >
    > >
    > > I usually do it in 3 steps:
    > >
    > > my $length = @array; # pretend it is a regular old array
    > >
    > > my $length = @{ }; # replace the _name_ of the array with a

    > block
    > >
    > > my $length = @{ $fx[0][0][0] }; # fill in the block with code

    > that
    > > # returns a reference to the
    > > # right kind of thingy
    > >
    > > --
    > > Tad McClellan SGML consulting
    > > Perl programming
    > > Fort Worth, Texas
     
    salsablr, Dec 20, 2004
    #4
    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. Mitchua
    Replies:
    5
    Views:
    2,777
    Eric J. Roode
    Jul 17, 2003
  2. =?Utf-8?B?SG96aQ==?=
    Replies:
    1
    Views:
    6,983
    Ken Cox [Microsoft MVP]
    Jun 2, 2004
  3. Sam
    Replies:
    3
    Views:
    14,146
    Karl Seguin
    Feb 17, 2005
  4. Replies:
    2
    Views:
    5,946
  5. Dan Manes
    Replies:
    1
    Views:
    740
    David Browne
    Apr 23, 2006
Loading...

Share This Page