From: "Wagner, David --- Senior Programmer Analyst --- WGO" <[EMAIL PROTECTED]> > Akens, Anthony wrote: > > I have two hashes, one containing data read in from a file, > > one with "current" data. I'd like to merge the two, adding > > any new keys and values into the hash, and for any keys that > > exist in both, I'd like the append the values onto the values > > for the same key in the original hash. > > foreach my $item ( keys %host_list ) { > $current_list{$item} .= ',' if ( exists $current_list{$item} ); > $current_list{$item} .= $host_list{$item}; > }
[mode nitpicking="on"] I think it'd be clearer to write it like this: foreach my $item ( keys %host_list ) { if ( exists $current_list{$item} ) $current_list{$item} .= ',' . $host_list{$item}; } else { $current_list{$item} = $host_list{$item}; } I think it'd be quicker as well and use warnings; would not complain (unless there actually existed some undef values in the %current_list of course). Another option could be eg: $current_list{$item} = (exists $current_list{$item} ? $current_list{$item} . ',' : '' ) . $host_list{$item}; but that way lies obfuscation. [/mode] Jenda ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>