Operator ->()

Discussion in 'Perl Misc' started by Subra, Mar 27, 2008.

  1. Subra

    Subra Guest

    Can some one pls tell me wts the meaning of "$topIter->next()" ?
    I know "->" is used for hash refs, but dont know when to use ->( ) !!!
     
    Subra, Mar 27, 2008
    #1
    1. Advertising

  2. Subra <> writes:

    > Can some one pls tell me wts the meaning of "$topIter->next()" ?


    This calls the method next() on the object $topIter. Read the perlobj
    documentation for more about this.

    > I know "->" is used for hash refs, but dont know when to use ->( ) !!!


    Beside being used for method calls, '->' is also with references in
    general for dereferencing. That is

    $aref->[0] - Using an array reference as an array
    $href->{foo} - Using an hash reference as an hash
    $sref->(1,2,3) - Using a subroutine reference (ie. call the sub)

    Read more about this in the perlref documentation under 'Using
    references', rule number 3.

    //Makholm
     
    Peter Makholm, Mar 27, 2008
    #2
    1. Advertising

  3. Subra

    Guest

    Subra <> wrote:
    > Can some one pls tell me wts the meaning of "$topIter->next()" ?


    It invokes method "next" on the object contained in $topIter.

    > I know "->" is used for hash refs, but dont know when to use ->( ) !!!


    Your example is not ->(), it is ->next(), or more generically, ->$method().
    They are quite different. The first is used on code-refs, the second on
    objects.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    The costs of publication of this article were defrayed in part by the
    payment of page charges. This article must therefore be hereby marked
    advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    this fact.
     
    , Mar 27, 2008
    #3
  4. Gunnar Hjalmarsson, Mar 27, 2008
    #4
    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. Jakob Bieling

    Q: operator void* or operator bool?

    Jakob Bieling, Mar 5, 2004, in forum: C++
    Replies:
    2
    Views:
    584
    Rob Williscroft
    Mar 5, 2004
  2. John Smith
    Replies:
    2
    Views:
    423
    Ivan Vecerina
    Oct 6, 2004
  3. Alex Vinokur
    Replies:
    4
    Views:
    3,051
    Peter Koch Larsen
    Nov 26, 2004
  4. Alex Vinokur
    Replies:
    3
    Views:
    5,029
    Jeff Schwab
    Mar 20, 2005
  5. Tim Clacy
    Replies:
    15
    Views:
    2,689
    Kanenas
    May 30, 2005
Loading...

Share This Page