| PerlJam | This is the second time in as many days as I've seen someone complain about autovivification. weird |
| rhizo | go figure |
| koye | well, i dont complain, just want to undestand it :) well it would be logical when you say $hash{'key'} = ('bla', 'blaaa') that you want it to make ref to array |
| rhizo | as for why you want to store a ref instead of a list or array, that's because a hash value must be a scalar not at all, koye: that list assignment is governed by how lists are evaluated in scalar context |
| PerlJam | koye: it's $hash{'key'} = [ 'foo', 'bar' ]; # Note the use of square brackets rather than round ones. |
| rhizo | see, above - the last list element is used |
| thorat | koye: do you want, $hash{'key'} = ['bla', 'blaaa'] it works |
| koye | PerlJam i know that |
| dazjorz | hmm |
| thorat | ah |
| koye | but why it isn't with () |
| dazjorz | So what do ye think :) paster.dazjorz.com - approved? |
| koye | couse hash only can have scalars |
| rhizo | pay attention, koye - i just explained that, dammit |
| PerlJam | koye: because that gives you a list of values rather than a single aggregate. |
| dazjorz | deparse: [@array] |
| buubot | [@array]; |
| dazjorz | deparse: \@array |
| buubot | (\@array); |
| rhizo | hash value is a scalar; that list is no different from any other list; ergo, assigned to a scalar its last element is used |
| dazjorz | which is faster? [@array] or \@array ? |
| PerlJam | dazjorz: That's an odd question. |
| dazjorz | PerlJam: Why is it then? |
| thorat | autovivification get's really useful when multiplied: push @{$hash{$inner}{$inner2}}, $var |
| dazjorz | eval: [@array] |
| buubot | dazjorz: [] |
| PerlJam | dazjorz: \@array is faster though since there isn't a copy involved. (But it may not be what you really want) |
| dazjorz | eval: \@array |
| buubot | dazjorz: [] |
| dazjorz | PerlJam: Ah yes, that's the difference [@array] = copy and reference; \@array = just reference |
| koye | heh, common mistake :) when you are using some @temp and then reference it somewhere |