in reply to question related to hash

In Perl's hashes, keys mush be unique. When you define the hash, each repeated key just overwrites the older value. In the real situation, you are probably getting the keys and values from something else than the source code itself, so you can concatenate the values:
while (get_tuple($key,$value)) { $hash{$key} .= $value; }

Replies are listed 'Best First'.
Re^2: question related to hash
by Anonymous Monk on Jun 24, 2011 at 10:42 UTC
    #!/usr/bin/perl -- use strict; use warnings; use List::Tuples qw' tuples '; Main( @ARGV ); exit( 0 ); sub Main { my %hash ; for my $tuple ( tuples [2] => rat => "acggghhh", mat => "dhhdhdhdh", rat => "fhhfjfjj", rat => "dggdgdgdg" ) { $hash{ $tuple->[0] } .= $tuple->[1]; } while ( my( $key, $value ) = each %hash ) { print "$key and $value \n"; } } __END__ rat and acggghhhfhhfjfjjdggdgdgdg mat and dhhdhdhdh