Reputation: 69
The arrow notation is asked about a lot here, but I can't seem to find the specific example I have. I would like to apologise in advance if I just missed it.
I have been given an assignment to correct some Perl code, but I simply do not understand what this line of code is supposed to do:
my $aref = [1,2,3,4];
my $x = $aref->{structure};
So as this is part of the assignment, the line itself could be the mistake, and there is more to the code too but my question is why is there an undefined keyword {structure}
? What does it do?
Upvotes: 0
Views: 62
Reputation: 126742
Have you tried running that code? What error message do you get? Do you understand it?
I agree that it's hard to know what sort of "fix" is expected, but I don't want to introduce you to something that you're not supposed to have covered yet. I think it's fair to say that deleting the second line is the most appropriate fix, but I doubt if that's what your tutor expects!
Do you know that [ 1, 2, 3, 4 ]
creates an anonymous array and returns a reference to it? If not then that is something you can google
So my $aref = [ 1, 2, 3, 4 ]
puts into $aref
a reference to an array (with four elements). Do you know how to access array elements from references? If not then perldoc perlreftut
(a tutorial) and perldoc perlref
are essential
And do you know how to access ordinary arrays, and ordinary hashes? I'm concerned that you think structure
is a "keyword". Maybe you need to read Perl variable types in perldoc perlintro
I hope that helps. If I get a better sense of where you're stuck I can give you much more appropriate help
Upvotes: 4