3 ms·
okay, in summary, I wanted to say. In Perl $ means scalar, @ means array and % means hash Those are variable types, you learn them by looking at the variable
by systems 18y ago
okay, in summary, I wanted to say.
In Perl $ means scalar, @ means array and % means hash
Those are variable types, you learn them by looking at the variable syntax or name
The value pointed to by those TYPED variables can be more complex, you can have integers, floats, strings, references, reference to a string, reference to array, reference to hash, array of strings, array of references etc .....
but the variable type won't tell you about these complex structures, it will only tell you that the value is $ scalar or @ array or % hash ... and in that there is no confusion, all the variables you mentioned above are typed scalar and can only point to values of type scalar
I understand your problem, since a scalar can be a reference to an array
you want to think that $ref = [] points to an array
but it doesn't it points to scalar which happens to be a reference to an array!
you can for example do this
my $ref = [];
$ref->[0]= 0;
say $ref->[0];
$ref = {};
$ref ->{0} = 1;
say $ref->{0};
but you can't do this
my $ref = [];
$ref->[0]= 0;
say $ref->[0];
## $ref = {};
$ref ->{0} = 1;
say $ref->{0};
because in $ref ->{0} = 1 the assignment is to value referenced to by te scalar, and this value type is not a hash and can't have a hash member {0}