in reply to Testing package membership

If you are testing for methods you can:

use strict; use warnings; use strict; package Abc; sub new { return bless {}, shift; } sub attrib1 { 1 } sub attrib2 { 10 } package main; my $abc = Abc->new (); for my $methName (qw(attrib1 attrib2 attrib3)) { next unless my $meth = $abc->can ($methName); print "Can $methName: ", $meth-> (), "\n"; }

Prints:

Can attrib1: 1 Can attrib2: 10

Perl reduces RSI - it saves typing

Replies are listed 'Best First'.
Re^2: Testing package membership
by FreakyGreenLeaky (Sexton) on Nov 21, 2008 at 09:01 UTC
    Thanks - but I need to step through almost a hundred packages (which is existing code) extracting those attribute values. So modifying the code and adding sub new() for each is problematic.

      There is a theme running through your last three questions, but it's not clear to me just what you are trying to achieve (although you could be trying to auto-document some legacy code). We may be able to help more if you let us in on the bigger problem.


      Perl reduces RSI - it saves typing
        Yes please! GrandFather you're absolutely right!