On Sat, Feb 16, 2002 at 07:07:28PM -0500, Geoffrey F. Green wrote: > my %table = ( > "key1" => > { search => "alpha", > shortname => "beta", > }, > "key2" => > { search => "gamma", > shortname => "delta", > }, > "key3" => > { search => "epsilon", > shortname => "whatever", > }, > ); > > foreach my $keys (%table) {
You say $keys here, and treat $keys as a key, but when you iterate over %table you're iterating over the list ('key1', $hashref1, 'key2', $hashref2, 'key3', $hashref3), i.e. both the keys -and- the values. You should be using keys(%table). foreach my $keys (keys %table) { ... } Also, I'd suggest naming it $key, not $keys; you're accessing one key at a time, not multiple keys. > print $table{$keys}->{search},"\n"; > print $table{$keys}->{shortname},"\n"; > }; > Camel's description of the error, and undefined variables, didn't clarify > matters for me, and unless I missed something fundamental, the FAQ didn't > have an answer to this conundrum. I'm not sure why you didn't understand the description, possibly because you didn't expect the error from what you were using. The problem occurred because you were trying to access $table{$hashref1}->{search}. There was no such key, so you got undef. > I also can't remember, off the top of my head, the sixth letter of the > Greek alphabet, but that's not important right now. zeta > 2. I also don't understand the extra newline I get between each pass of the > foreach loop. With warnings disabled, the output is as follows: Just because one of the values in your print statement is undefined doesn't mean the entire print statement is ignored. You have: print $table{$keys}->{search}, "\n"; If $table{$keys}->{search} is undefined, it's stringified to "" and a warning is issued. So, in effect, you have: print "", "\n"; Which prints just a newline, thus the "extra" whitespace. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]