Operator ->()

S

Subra

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 ->( ) !!!
 
P

Peter Makholm

Subra said:
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
 
X

xhoster

Subra said:
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.
 
G

Gunnar Hjalmarsson

Subra wrote:

[ exactly the same question as was posted to the beginners list a few
minutes earlier ]

DO NOT DO THAT !!!
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top