Hi,
I've solved part of my problem using something like this:
while (<line>) {
chomp;
($product, $geo, $type) = split(/\s/,$line, 3);
$list{$product} += 1; #gives me a count of the events
push @{ $list{$product} }, $geo;
@{ $list{$product} }->[$geo]++;
}
which I think stores the product (e.g. records, penguins) as a key, with
$list{$product} holding the count and then $geo (the various cities) pushed
as an array on the end.
I'm not entirely certain if this storing the data correctly. It's not clear
to me how to get at the array where the $geo data are. (I've read perlreftut
many times but can't get it).
something like this:
foreach $sale (sort keys(%$list) {
printf "$sale $list{$sale} # gives me the total by product
How do I get total by city?
I'd appreciate any help and/or some pointers to a tutorial on referencing
that a newbie can grok. thanks.
sean
> -----Original Message-----
> From: Sean Pfister [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, September 18, 2001 6:27 PM
> To: [EMAIL PROTECTED]
> Subject: assigning complex data into a hash (of hashes?)
>
>
> Hi,
>
> I have a data file in which each line is an instance of an event (e.g. a
> sale). The file contains info about where the event happened (the city,
> state, country), the type of event (catalogue, telephone,
> in-store) and some
> other classification data (cash, credit card, indentured labor, firstborn
> child).
>
> Data fields are:
> timestamp
> product_name
> geo1 (e.g San Francisco)
> geo2 (e.g. California)
> geo3 (e.g. usa)
> geo4 (West)
> type1 (store)
> type 2 (cash, etc.)
>
>
> So, if there were 5 sales in San Francisco, then there will be 5 lines in
> the text file.
>
> I want to slurp in the whole file and put it in a hash structure of some
> sort so I can count totals within each field.
> e.g, print out a total of sales by State or by City or by region. I might
> not know how many cities are in the field or how many state. The key will
> always be the product_name field.
>
>
> Do I need to make an array for each field, like this:
>
> while (<$line>) {
> ($time, $product, etc.) = split(/,/,$line, 8);
> push @{ $hash1{$product} }, $geo1;
> push @{ $hash1{$product} }, $geo2;
> etc.
>
> and then count the number of entries by category later on, when
> I'm looping
> through the appropriate array? (That is, for each "city" in geo1, count
> it--5 "San Francisco's" means 5 sales in SF.
>
> I suspect that there's a better structure, which allows me to total the
> counts for each field as I load it. And that I can use anonymous arrays to
> load in the whole thing once.
>
> I'd very much appreciate any advice.
>
> Best,
>
> Sean
>
>
>
>
>
>
>
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, September 18, 2001 3:24 PM
> > To: [EMAIL PROTECTED]
> > Subject: autovivification of typeglobs
> >
> >
> > Gurus,
> > The Camel ( 3rd Ed. ), says, on page 385-386
> > sub TIEHANDLE {
> > ....
> > open my $self, $from, @_ or croak "can't open $from@_:$!";
> > ....
> > }
> >
> > and then,
> > " ... the my $self furnishes undefined scalar to open, which knows to
> > autovivify it into a typeglob. .... " and further mentions
> > autovivifying a
> > scalar ($$$self), an array (@$$self) etc.
> > I have read and reread the above and related typeglob material
> many times
> > but somehow I don't understand what is going on here. If $self is a
> > reference then, the above should read $$self, @$self etc. What is the
> > extra $ doing in there? Any help in taking apart the above expressions?
> > Also, could somebody give any online pointers (: references :), that
> > describe Typeglobs, in more detail?
> >
> > --------- Thanks in advance,
> > Atul
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]