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

Discussion in 'Perl Misc' started by Unknown Poster, May 24, 2004.

  1. 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.
     
    Unknown Poster, May 24, 2004
    #1
    1. Advertising

  2. Unknown Poster

    Eric Bohlman Guest

    (Unknown Poster) wrote in
    news::

    > 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.
     
    Eric Bohlman, May 24, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fily Salas
    Replies:
    4
    Views:
    518
    Fily Salas
    Apr 15, 2011
  2. David Petrou

    Q: good time to buy the camel book?

    David Petrou, Oct 13, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    149
    David Oswald
    Oct 13, 2003
  3. Sara

    Why Camel is Better than Perldoc

    Sara, Nov 11, 2003, in forum: Perl Misc
    Replies:
    6
    Views:
    151
    Eric J. Roode
    Nov 12, 2003
  4. Suresh Govindachar

    Camel book: why invoke in the manner @{[&whowasi]}?

    Suresh Govindachar, Aug 11, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    159
    Brian McCauley
    Aug 12, 2004
  5. Vijai Kalyan
    Replies:
    2
    Views:
    184
    Vijai Kalyan
    Oct 17, 2004
Loading...

Share This Page