Re: dereferencing an array - Pt 2

2006-02-11 Thread Eric Lease Morgan
On Feb 11, 2006, at 8:16 AM, Brad Baxter wrote: I have this sample data structure: my %profile = ( 'subjects' => { 'astronomy' => { 'telescope world' => 'http://telescope.com', 'stars r us' => 'http://websters.com', 'asto magazine' => 'http://oxford.ed

Re: dereferencing an array - Pt 2

2006-02-11 Thread Brad Baxter
Short answer: $profit{ $facet }{ $term }{ $resource } = $url; Example: #!perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Terse++; $Data::Dumper::Indent--; my %profit; while( ) { chomp; my( $resource, $url, $term, $facet ) = split /,/; $profit{ $facet }{ $term }{ $res

Re: dereferencing an array - Pt 2

2006-02-10 Thread Eric Lease Morgan
On Feb 10, 2006, at 5:41 PM, Bruce Van Allen wrote: foreach my $facet_key (keys %facets) { print "$facet_key\n"; my %sub_hash= %{ $facets{$facet_key} }; foreach my $sub_key (keys %sub_hash) { print "\t$sub_key\n"; my %inner_hash= %{ $sub_hash{$sub_key} }; foreach my $i

Re: dereferencing an array - Pt 2

2006-02-10 Thread Bruce Van Allen
My previous message got kinda long, so here's some tested Perl that does just what Eric's last message asked for: #!/usr/bin/perl -w use strict; my %facets = ( 'tools' => { 'dictionaries' => { 'websters' => 'http://websters.com', 'oxford' => 'http://oxford.edu'

Re: dereferencing an array

2006-02-10 Thread Bruce Van Allen
On 2/10/06 Eric Lease Morgan wrote: >On Feb 10, 2006, at 3:51 PM, Jonathan Gorman wrote: >>> How do I loop through a reference to an array? >>> >>> I have the following data structure: >>> >>> my %facets = ( >>>'audiences' => [('freshman', 'senior')], >>>'subjects' => [('music', 'history'

Re: dereferencing an array

2006-02-10 Thread Eric Lease Morgan
On Feb 10, 2006, at 3:58 PM, Eric Lease Morgan wrote: Now I'm going to make each value in the referenced array a reference to a hash; I'm going to make my data structure deeper. 'More later. Since that worked so well, I'll ask this question. Given the following data structure, how do I p

Re: dereferencing an array

2006-02-10 Thread Spencer Anspach
Yes, mea culpa, Johathan is right. In addition to the typo, I didn't recognize that the example given isn't a hash of hashes but only a hash of arrays (I'm too used to doing hashes of hashes, which are just so darn much fun). foreach my $key1 (sort keys %facets) { foreach my $key2 (@{$facets{$ke

Re: dereferencing an array

2006-02-10 Thread Eric Lease Morgan
On Feb 10, 2006, at 3:51 PM, Jonathan Gorman wrote: How do I loop through a reference to an array? I have the following data structure: my %facets = ( 'audiences' => [('freshman', 'senior')], 'subjects' => [('music', 'history')], 'tools' => [('dictionaries', 'catalogs')] );

Re: dereferencing an array

2006-02-10 Thread Jonathan Gorman
Ergg, just realized my copy of Programming Perl is at home. Ah well, the old noggin is pretty sure how to do this. Quick short answer, @{$facets{$key}}..so foreach $foo (@{$facets{$key}}) { print "Hello, I'm $foo. Pleased to meet ya.\n"; } or something along those lines Jonathan T. Gorm

Re: dereferencing an array

2006-02-10 Thread Spencer Anspach
foreach my $key1 (sort(keys(%facets))) { foreach my $key2 (sort(keys(%facets{$key1))) { print " $key1 / $key2 \n"; } } Spencer On 2/10/06, Eric Lease Morgan <[EMAIL PROTECTED]> wrote: > > How do I loop through a reference to an array? > > I have the following data structure: > >my %fa

dereferencing an array

2006-02-10 Thread Eric Lease Morgan
How do I loop through a reference to an array? I have the following data structure: my %facets = ( 'audiences' => [('freshman', 'senior')], 'subjects' => [('music', 'history')], 'tools' => [('dictionaries', 'catalogs')] ); I can use this code to get the keys for %facets: