Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   questions re "Using the Arrow Operator" in Camel 3ed (http://www.velocityreviews.com/forums/t886558-questions-re-using-the-arrow-operator-in-camel-3ed.html)

Unknown Poster 05-24-2004 12:48 AM

questions re "Using the Arrow Operator" in Camel 3ed
 
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.

Eric Bohlman 05-24-2004 01:11 AM

Re: questions re "Using the Arrow Operator" in Camel 3ed
 
use63net@yahoo.com (Unknown Poster) wrote in
news:c62e93ec.0405231648.290d1d2f@posting.google.c om:

> 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.


All times are GMT. The time now is 08:11 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.