At 06:18 PM 6/11/01 +0200, Ruth Albocher wrote:
>hi
>I have started learning perl recently as I need to maintain someone's
>old code.
>under 'use overload'  along with other 'normal' overloaded operators he
>has: qw("", stringify)
>i understand each word separately.. but.. where's it invoked and how?

It's really pretty simple.  "use" causes a compile-time loading of 
overload.pm, which reads in its arguments and associates subroutines with 
certain operations like addition, etc.  Then whenever a variable that has 
been told it belongs to the overloaded class is used in one of those 
operations, instead of the normal (say) addition being done, the designated 
subroutine is called instead.

In your case, the routine 'stringify' (which you'll find lower down in that 
same code) will be called whenever a variable is used in a string context, 
for instance, interpolated in double quotes: "Hello, $friend".

>is there a recommended site i can look things like this up (other than
>the man and the camel)?
>thanks,
>ruthie

While the syntax and semantics of overloading are fairly easy to 
understand, its use is usually considered advanced because it requires 
understanding O-O programming in Perl.  If you've only just started 
learning Perl you're trying to run before you can walk.  Bummer, but there 
it is.  My advice is to get a copy of the Llama (Randal needs a new SUV :-) 
and make sure you can understand it.  Otherwise you'll be on a shaky 
foundation.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com

Reply via email to