in reply to The CORRECT thinking behind the {}s and the ()s.
To remember the braces for references, I use this logic:
So just remember how you access elements in an array/hash, and that will tell you which braces to use for anonymous refs as well. It won't take long for it to become second nature.# to access a member of an ARRAY, use [] $array[0] = "hello"; # so to define an anonymous array reference, use [] as well $array_ref = [ "Hello", "World" ]; # to access a member of a HASH, use {} $hash{'foo'} = "bar"; # so to define an anonymous hash reference, use {} as well $hash_ref = { foo => 'bar', xyz => 'abc' };
blokhead
|
|---|