questions re "Using the Arrow Operator" in Camel 3ed

U

Unknown Poster

I've read this section (page 253 of the 3rd edition of Programming Perl)
enough to confuse myself quite nicely.

One sentence reads, "If the next thing after the arrow is a bracket or a
brace, the left operand is treated as a reference to an array or hash,
respectively ..."

I just don't see how this code, and its explanation, square with that quote:

print $array[3]->{"English"}->[0];

" ... the fourth element of @array is intended to be a hash reference ..."

Isn't it the fourth element of the array referenced by (the poorly named)
$array ?


When there is more than one arrow operator in an expression, is it true
that only the "initial funny character" is omitted?

When the arrow operator is removed when it would be "between brackets
or braces, or between a closing bracket or brace and a parenthesis for
an indirect function call", is the meaning of the expression changed
in any way?

Anyone know what is meant by "ordinary arrays"?

I'll admit to be so baffled by the final "listref" expressions in this
section that I can't think of a good question.
 
E

Eric Bohlman

(e-mail address removed) (Unknown Poster) wrote in
I've read this section (page 253 of the 3rd edition of Programming
Perl) enough to confuse myself quite nicely.

One sentence reads, "If the next thing after the arrow is a bracket or
a brace, the left operand is treated as a reference to an array or
hash, respectively ..."

I just don't see how this code, and its explanation, square with that
quote:

print $array[3]->{"English"}->[0];

" ... the fourth element of @array is intended to be a hash reference
..."

Isn't it the fourth element of the array referenced by (the poorly
named) $array ?

Nope. "$array" all by itself refers to a scalar variable that has nothing
to do with @array. "$array[3]", OTOH, means "the fourth element of
@array". It's followed by an arrow, and then an opening brace so, voila!
it's treated as a reference to a hash. This means that
"$array[3]->{"English"}" will be whatever value the hash being referenced
has for the key "English". And that in turn is followed by an arrow
followed by a bracket, so the hash value is now treated as a reference to
an array (which almost certainly isn't @array), and the whole expression
retrieves the value of the first element of that array.
When there is more than one arrow operator in an expression, is it
true that only the "initial funny character" is omitted?

When the arrow operator is removed when it would be "between brackets
or braces, or between a closing bracket or brace and a parenthesis for
an indirect function call", is the meaning of the expression changed
in any way?
No.

Anyone know what is meant by "ordinary arrays"?

The kind of array that you name "@array" or "@emails" or what have you.
I'll admit to be so baffled by the final "listref" expressions in this
section that I can't think of a good question.

perldoc perlreftut might help unconfuse you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top