in reply to running unknown methods

I don't think I'd really recommend it but I think you are trying to do something like this:

#!/usr/bin/perl -w use strict; package Foo; sub new { bless { "_foo", 1, "_bar", 1, "_qux", 1 } } sub runTests { my ($self) = @_; for my $symname (sort keys %{$self}) { local *sym = ref($self)."::$symname"; &sym if defined(&sym) and $symname =~ /^_.*/; } } # sub runTests sub _foo { print "_foo called\n" } sub _bar { print "_bar called\n" } package main; my $foo = Foo->new(); $foo->runTests();

There are a couple of issues with that approach though. One of which is that the subs won't be called as methods at all. They'll be invoked as regular old subroutine calls. The other issue is that it doesn't take inheritance into account. A better approach might be something like:

sub runTests { my ($self) = @_; for my $symname (sort keys %$self) { next unless $symname =~ /^_/; $self->$symname() if $self->can($symname); } }

I think that's somewhat more readable as well. It depends on exactly what behavior you want too.

Update: After seeing some of the other posts it looks like you are actually trying to walk the symbol table of the package the object is blessed into and then to call each of those methods on the object. With that in mind, that second sub would look more like this:

sub runTests3 { my ($self) = @_; no strict 'refs'; for my $symname (sort keys %{ref($self).'::'}) { next unless $symname =~ /^_/; $self->$symname() if $self->can($symname); } }
-sauoq
"My two cents aren't worth a dime.";