on Tue, 07 May 2002 12:02:31 GMT, [EMAIL PROTECTED] (Martin A. Hansen)
wrote: 

> i would like to print the records based on a search agianst the
> content of the arrays. 
> 
> im trying something like this, but its not working. im not good at
> dereferencing stuff. 

In that case it is always better to be as explicit as possible, as 
shown below. If you don't want to search the subkey space, you can 
leave out the second loop, setting '$sk' to the desired subkey 
instead.


I'm sure somebody will come up with a nifty solution involving 
multiple grep's and/or map's, but when you look at this in a month or 
two, will you still immediately see what it's supposed to do? 


#! perl -w
use strict;

my $records = {
    'bleh' => { a => ['x', 'y', 'z'],
                b => ['u', 'v', 'w'], 
              },
};

my $pat = "w";

for my $k (keys %$records) { # loop over keys
   for my $sk (keys %{$records->{$k}}) { # loop over subkeys
      foreach (@{$records->{$k}{$sk}}) { # loop over array values
         print "'$pat' found at '$k/$sk'\n" if /$pat/;
      }
   }
}

-- 
felix


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to