Thread Hash im Skalaren Kontext 3/8 und so (15 answers)
Opened by rosti at 2012-08-16 18:32

pq
 2012-08-16 19:02
#161080 #161080
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
die erste zahl steht *nicht* für die anzahl der keys.
kannst du ja selbst ausprobieren.
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
perl -wE'for (1..20) { $hash{$_}++; say scalar %hash; }'
1/8
2/8
3/8
3/8
4/8
5/8
6/8
7/16
8/16
9/16
10/16
10/16
10/16
11/16
11/16
14/32
14/32
15/32
15/32
15/32

perldoc perldata:
Quote
If you evaluate a hash in scalar context, it returns false if the hash is empty. If there are any
key/value pairs, it returns true; more precisely, the value returned is a string consisting of the
number of used buckets and the number of allocated buckets, separated by a slash.
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread Hash im Skalaren Kontext 3/8 und so