Re: length of an array in a struct in an array of structs in a struct in an array of structs
- From: "Tuan Bui" <bigtrick@xxxxxxxxx>
- Date: 28 Jul 2005 12:05:18 -0700
Paul Lalli wrote:
> Tuan Bui wrote:
> > I do know that
> >
> > scalar(@{@VisitArray[$i]->PSearchStructArray})
> >
> > will return the length of PSearchStructArray well enough though.
>
> Perhaps I'm having a brain cramp here, but I can't especially see how
> that could work. The arrow notation is used for either A)
> dereferencing a hash or array reference to get at its elements or B)
> calling a method of an object or class.
I am using Class::Struct, and indeed i am implicitly calling methods
from it. It indeed returns the correct lengths that I want.
>
> In other words, I can see that
> $VisitArray[$i]->{PSearchStructArray}
> might return the value of the hash referenced by $VisitArray[$i] at key
> 'PSearchStructArray', or
> $VisitArray[$i]->PSearchStructArray()
> might call a method of the object $VisitArray[$i], which could in turn
> return a list of values.
>
> I cannot, however, discern any way in which
> $VisitArray[$i]->PSearchStructArray
> could return "the length of PSearchStructArray".
>
> Can you please enlighten me by showing the code that creates your
> classes and objects?
struct( VisitStruct => {
VisitID => '$', # ID number of this visit
PSearchStructArray => '@', # array of psearch structures
(PSearchStruct type)
});
struct( PSearchStruct => {
ClickPathArray => '@', # array of click path elements (scalar type)
Before => EventStruct, # event that occured before psearch
(EventStruct type)
After => EventStruct, # event that occured after psearch
(EventStruct type)
ReachedItemScreen => '$', # bool that is true if user reached item
detail screen (scalar type)
ReachedCatalogPage => '$', # bool that is true if user reached
catalog screen (scalar type)
ReachedBookmarkScreen => '$', # bool that is true if user bookmarked
item (scalar type)
# note: in order to set this bool, we will have to go one
beyond the
# item detail screen when traversing events
});
struct( EventStruct => {
EventCode => '$', # code of event (scalar type)
EventDesc => '$', # short description of event (scalar type)
});
@VisitArray has VisitStructs pushed onto it elsewhere in the code.
>
> (For why I replaced your '@' with '$' in each example, please see:
> perldoc -q difference
> )
Neat... thanks for pointing this out.
>
> Paul Lalli
Thanks.
To everyone else who has responded, thank you also! I am testing out
your solutions as we type.
Tuan
.
- Follow-Ups:
- References:
- Prev by Date: Re: multidimensional insertion order
- Next by Date: Re: Perl DBI - How to handle large resultsets?
- Previous by thread: Re: length of an array in a struct in an array of structs in a struct in an array of structs
- Next by thread: Re: length of an array in a struct in an array of structs in a struct in an array of structs
- Index(es):