in reply to question related to hash
is equivalent to#!/usr/bin/perl -w use strict; my ( $key, $value ); my %hash = ( rat => "acggghhh", mat => "dhhdhdhdh", rat => "fhhfjfjj", rat => "dggdgdgdg" ); while ( ( $key, $value ) = each %hash ) { print "$key and $value \n"; }
That is how hash assignment works, duplicate keys overwrite the value. If you want to append to rat, you might write#!/usr/bin/perl -w use strict; my ( $key, $value ); my %hash = ( rat => "acggghhh", mat => "dhhdhdhdh", ); $hash{rat} = "fhhfjfjj"; $hash{rat} = "dggdgdgdg"; while ( ( $key, $value ) = each %hash ) { print "$key and $value \n"; }
$hash{rat} .= "fhhfjfjj"; $hash{rat} .= "dggdgdgdg";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: question related to hash
by aanriot (Sexton) on Jun 24, 2011 at 11:19 UTC |