🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.perl
Article #52137

Re: %hash = (a => 1, b => 2, a => 3)

#52137
From: Szymon Sokół
Date: Sun, 26 Dec 2010 23:52
38 lines
2559 bytes
On Sun, 26 Dec 2010 11:39:30 +0000 (UTC), Stachu 'Dozzie' K. wrote:

> Damn, chłopaki, wspomóżcie. W którym perldocu jest wpisane, że przy
> inicjalizacji hasza listą, jeśli klucz się powtórzy, brana jest wartość
> z ostatniego powtórzenia? Znaczy, z kodu poniżej wyjdzie liczba 3:
> #v+
> %hash = (
>   a => 1,
>   b => 2,
>   a => 3,
> );
> print $hash{a};
> #v-
> 
> Że tak jest, to łatwo sprawdzić, ale mnie interesuje gwarancja
> pochodząca z dokumentacji, a jakoś nie mogę tego znaleźć (perldata,
> perldsc, perlfaq).

W dokumentacji nie ma, a pytanie, sądząc z pobieżnego guglania, pojawiało
się parokrotnie na różnych forach. Najbliższe autorytatywnej odpowiedzi jest
chyba to, co napisano w http://perl101.org/hashes.html 

Combine hashes with list assignment

To combine two hashes, look at them as lists and assign them to a hash.

    my %new_hash = (%hash1, %hash2);

The right-hand side of the equals is a long list of key/value pairs from
both of the hashes. The list is then assigned to %new_hash. If any keys in
%hash2 duplicate keys in %hash1, the %hash2 key/value pair take priority
because they're assigned later.

-- 
Szymon Sokół (SS316-RIPE) -- Network Manager                                 B
Computer Center, AGH - University of Science and Technology, Cracow, Poland  O
http://home.agh.edu.pl/szymon/ PGP key id: RSA: 0x2ABE016B, DSS: 0xF9289982  F
Free speech includes the right not to listen, if not interested -- Heinlein  H
Technical Details
Message-ID: <1gfu0m18k83oc.dlg@falcon.sloth.hell.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!.POSTED!dustpuppy.sloth.hell.pl!not-for-mail
References: <if79hi$bnf$1@solani.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!.POSTED!dustpuppy.sloth.hell.pl!not-for-mail
From: Szymon Sokół
 <szymon@bastard.operator.from.hell.pl>
Newsgroups: pl.comp.lang.perl
Subject: Re: %hash = (a => 1, b => 2, a => 3)
Date: Mon, 27 Dec 2010 00:52:48 +0100
Organization: Guy Fawkes Society
Lines: 38
Sender: szymon@news.agh.edu.pl
Message-ID: <1gfu0m18k83oc.dlg@falcon.sloth.hell.pl>
References: <if79hi$bnf$1@solani.org>
NNTP-Posting-Host: 89-78-159-131.dynamic.chello.pl
Mime-Version: 1.0
X-Trace: news.agh.edu.pl 1293407792 21917 89.78.159.131 (26 Dec 2010 23:56:32 GMT)
X-Complaints-To: abuse@agh.edu.pl
NNTP-Posting-Date: Sun, 26 Dec 2010 23:56:32 +0000 (UTC)
User-Agent: 40tude_Dialog/2.0.15.1 Hamster/2.1.0.11
X-Face: xic?6f"rD)k-tM.]L]A6l4W7_aGt({}&{D,hiRI.8cPtf,1F.w@Qkl!vr23o1UY-BfXO$p< hk5>ijB?eBy)?!C<@)+%U\&`1X)MJ>.i.qgkY]4mvL62j<|xJRG/5:7:l8q]x;v!)Bz^r/!yG8DxoD -@fnC,g]BAXj
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit