#perl - Sun 18 Feb 2007 between 18:13 and 18:19



PerlJamThis is the second time in as many days as I've seen someone complain about autovivification.
weird
rhizogo figure
koyewell, 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
rhizoas 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
PerlJamkoye: it's $hash{'key'} = [ 'foo', 'bar' ]; # Note the use of square brackets rather than round ones.
rhizosee, above - the last list element is used
thoratkoye: do you want, $hash{'key'} = ['bla', 'blaaa']
it works
koyePerlJam i know that
dazjorzhmm
thoratah
koyebut why it isn't with ()
dazjorzSo what do ye think :)
paster.dazjorz.com - approved?
koyecouse hash only can have scalars
rhizopay attention, koye - i just explained that, dammit
PerlJamkoye: because that gives you a list of values rather than a single aggregate.
dazjorzdeparse: [@array]
buubot[@array];
dazjorzdeparse: \@array
buubot(\@array);
rhizohash value is a scalar; that list is no different from any other list; ergo, assigned to a scalar its last element is used
dazjorzwhich is faster? [@array] or \@array ?
PerlJamdazjorz: That's an odd question.
dazjorzPerlJam: Why is it then?
thoratautovivification get's really useful when multiplied: push @{$hash{$inner}{$inner2}}, $var
dazjorzeval: [@array]
buubotdazjorz: []
PerlJamdazjorz: \@array is faster though since there isn't a copy involved. (But it may not be what you really want)
dazjorzeval: \@array
buubotdazjorz: []
dazjorzPerlJam: Ah yes, that's the difference
[@array] = copy and reference; \@array = just reference
koyeheh, common mistake :)
when you are using some @temp and then reference it somewhere

Page: 4 11 18 25 32 39 46 53 60 67 74 

IrcArchive