@LanX One workaround would be to surround every value with quotes "$h{bla}" , to enforce a copy. -- thank you. That's good hint. I have tried also $h{bla} // "".
@haukex
I'm pretty sure the answer is the same as in your previous thread that you referenced: map is providing lvalue context to its args, while the other two examples of string concatenation do not, hence the hash value is autovivified.
Yess.. this is the same problem. Sorry for coming again with the same...
$ perl -wMstrict -MData::Dump -e 'my %h; map{$_} $h{X},"$h{Y}"; dd
+\%h'
Use of uninitialized value $h{"Y"} in string at -e line 1.
{ X => undef }
Hmmmm... only one warning... It doesn't warn about X. Educative example.
I'm curious why you have so many issues with autovivification? Personally, I hardly ever do, because I use exists, or keys when looping over multiple hash keys.
In my company (dubielvitrum.com, manufacturer of mirrors) there is manufacturing system written in perl. And all data is kept in structured files, with strict data types (numbers, identifiers, quoted texts). This data is checked carefully on input and output. When undef gets somehow into hash then error is thrown. So I have to search how undef got injected into data structures. Original piece of code that made that error was like this:
$wi{OrderUniqueId} = join " ", grep { $_ ne "" } map { unquote
+_text($_) }
($ty eq "need" ? "Zamów" : "Posia"), $$it{name}, $$it{
+para}{Termin}, $$it{para}{Ile}, seq_num(6);
To build OrderUniqueId I take (1) word "Zamów" or "Posia" (2) name of item (3) parameter "Termin" (4) parameter "Ile" (6) some sequence number -- take all non empty of these, join them with spaces.
$wi{OrderUniqueId} = join " ", grep { $_ ne "" } map { unquote_text($_
+) }
($ty eq "need" ? "Zamów" : "Posia"), $$it{name}, $$it{
+para}{Termin} // "", $$it{para}{Ile} // "", seq_num(6);
Normally when working with perl I hardly ever got errors from autovivification when aliased with grep or map.
|