[Munich-pm] Hash mit Hash verschmelzen

Robin Clarke robin at robinclarke.net
Thu Jan 12 00:38:25 PST 2012


my @a = qw/ 089 030 040 089 030 040 040/;

my %hash;
$hash{$_}++ for @a;

my %areacode = (
"089"   =>      "Muenchen",
"030"   =>      "Berlin",
"040"   =>      "Hamburg",
);

printf( "%s\n", join "\n", map{ "$_ $hash{$_} mal ($areacode{$_})"
}sort{ $hash{$b} <=> $hash{$a} }keys %hash );


Best winds,
-Robin-

On 12/01/12 09:28, Stefan Bauer wrote:
> Hallo Mongers,
>
> ich stehe vor dem Problem, bei einer Ausgabe ein Hash mit einem Hash zu verschmelzen. Jedoch bin ich weit entfernt davon, mir einen Reim zu machen und bitte euch um Hilfe:
>
> @a = qw/ 089 030 040 089 030 040 040/;
>
> my %hash;
> $hash{$_}++ for @a;
>
> my @sortiert = map{ "$_ $hash{$_} mal" }sort{ $hash{$b} <=> $hash{$a} }keys %hash;
> print join "\n", @sortiert;
>
>
> %areacode = (
> "089"   =>      "Muenchen",
> "030"   =>      "Berlin",
> "040"   =>      "Hamburg",
> );
>
>
> Das Hash mit den Areacodes soll also in der print-Ausgabe integriert werden.
>
> Derzeit erhalte ich:
>
> 040 3mal
> 030 2mal
> 089 2mal
>
> Ich hätte jedoch gerne hinter der Nummer in Klammern noch den passenden Ort aus dem areacode-Hash.
>
>
> Danke im Voraus
>
>
> Stefan
> _______________________________________________
> Munich-pm mailing list http://munich.pm.org/
> Munich-pm at pm.org
> http://mail.pm.org/mailman/listinfo/munich-pm

-- 
Best winds,
-Robin-
~:)

# My Github repository with mostly perl code
# https://github.com/robin13


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 302 bytes
Desc: OpenPGP digital signature
URL: <http://mail.pm.org/pipermail/munich-pm/attachments/20120112/5725e11b/attachment.bin>


More information about the Munich-pm mailing list