On Monday 10 September 2007, Palit, Nilanjan wrote:
> I have to do some format conversions, so I'm defining subroutines like
> "sub FormatConv_X2Y()". At this point I have only a few of the format
> conversions defined & I haven't gone through the entire dataset to know
> all the format conversions needed. So I'd like to check whether a
> specific format conversion subroutine is defined before I call it (all
> the subroutine names will be of the form "FormatConv_X2Y") -- is there a
> way to do that? In other words, is there a way to find out whether a
> subroutine is defined before calling it?
>

The best way is probably:

if (defined(my $func = __PACKAGE__->can("FormatConv_${from}2${to}")))

Then you can also do:

$func->(@args).

Regards,

        Shlomi Fish

> I'm guessing it might involve looking up the symbol table, but don't
> know any specifics. Any help would be much appreciated.
>

No need for this in this particular case.

Regards,

        Shlomi Fish

> Thanks,
>
> -Nilanjan
>
>
> _______________________________________________
> Boston-pm mailing list
> [email protected]
> http://mail.pm.org/mailman/listinfo/boston-pm



-- 

---------------------------------------------------------------------
Shlomi Fish      [EMAIL PROTECTED]
Homepage:        http://www.shlomifish.org/

If it's not in my E-mail it doesn't happen. And if my E-mail is saying
one thing, and everything else says something else - E-mail will conquer.
    -- An Israeli Linuxer
 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to