whoa. look at this line of perl:
-
whoa. look at this line of perl:
$ip_ua_count{$ip}{$agent}++;
Two auto-initializations are going on here
1. if $ip_ua_count{$ip}{$agent} doesn't exist, its auto-initialized to 0
2. if $ip_ua_count{$ip} dosen't exist it's auto-initialized to an empty hashmapthe first one I expected but the second one was a really pleasant surprise. I don't have to write an annoying "if the hashmap doesnt exist, put an empty hashmap there" line of code before this, it just does that for me
-
@artemis does it always initialize integers to the identity element for the operation? Like, what does it initialize to if you change it from ++ to
*= 2
-
@cliffle it initializes to 0 for all of them., so for *= 2 it will be assigned to the result of 0 * 2.
But also, it seems to emit a warning when it auto-initializes during ANY operation except for the set of ++, --, +=, -=. Like if you were to write $hash{x} = $hash{x} + 1 and $hash{x} was uninitialized that would warn, because now you're using something uninitialized outside of an increment/decrement context
-
@artemis FWIW, the Perl documentation calls this 'auto-vivification'.
-
-
-
Alexandra Magin 🏳️🌈replied to Riley S. Faelan on last edited by
-
Riley S. Faelanreplied to Alexandra Magin 🏳️🌈 last edited by
@recursive Yeah. Types could be used for so much more.
-