SPUG: code reference callback on a class method

ced at carios2.ca.boeing.com ced at carios2.ca.boeing.com
Fri May 31 13:21:56 CDT 2002


> How do you do a callback on a class method?  For
> example:

> Zub process_files {
>   my $self = shift;
>   # stuff
> }

> Zub process {
>   my $self = shift;
>   find(\&process_files, @ARGV);
> }

> I'm trying to get the first argument of find() to be a
> callback using $self->process_files()

> I went to the books on subroutines and references, but
> I'm stuck.  Any help would be greatly appreciated.

Take a look at "11.8 Creating References to Methods" in the 
Perl Cookbook by T. Christiansen.

Briefly, you'll need to create a closure, eg,

   my $mref = sub { $self->process_files() };
   ...

   find( $mref, @ARGV );



hth,
--
Charles DeRykus

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org




More information about the spug-list mailing list