Confused between anonymous array and anonymous hash
my $ref = [{Shu => 21}, {Zee => 22}, {Haa => 11}];
a) hash containing anonymous hashes. b) anonymous array of references to anonymous hashes. c) array of arrays d) anonymous hash of hash references. e) multi-dimensional array i am confused between (b) and (d).Which one is appropriate. Can anyone please explain me the difference. Thank You.. |
"man perlreftut" should help you out.
Also Code:
perl -e 'my $ref = [{Shu => 21}, {Zee => 22}, {Haa => 11}]; print $ref, "\n"; print ${$ref}[0], "\n"' |
First, check out http://www.perlmonks.org
Now on to your question: the variable $ref:
In Perl, an array is a one-dimensional structure whose elements are accessed by a zero-based numeric index. A hash is a one-dimensional structure whose elements are accessed by string key-values, such as (in this case) "Shu," "Haa," and "Zee." A reference is simply "a thing," specifically a scalar thing, which "refers to" something else ... that is to say, "indirectly." A reference can refer to any sort of thing. It is a good idea to prefix all programs with: use strict; use warnings;. Do this as a strict matter of routine, every time. Perl is otherwise "do what I (think you) mean." It can allow you to write stuff that isn't what you thought you were writing, unless you, in this way, ask for more stricture and warnings. Do so. |
Moderator Response
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
|
Quote:
Instead anonymous array references and anonymous hash references do exist. For simplicity/brevity the above references are called anonymous arrays and anonymous hashes. Unofficially :). |
Quote:
|
Quote:
|
Quote:
Code:
sergei@amdam2:~> perl -e 'print ref([1,2]), "\n"' Code:
ref EXPR |
All times are GMT -5. The time now is 08:19 PM. |