On Fri, Jul 25, 2008 at 12:38:49 +0000, Mikhael Goikhman wrote:

> for my $thing (@things) {
>       my $type = ref($thing);
>       # do something accourding to $type, for example, just print it
>       print defined $thing ? "$thing is of type '$type'\n" : "undef\n";
> }

Usually what I like to do is:

        sub handle_thing {
                my ( $self, $thing ) = @_;
                my $type = ( blessed($thing) ? "object" : ( ref($thing) || 
"scalar") );
                my $method = $self->can("handle_$type") || "handle_fallback";
                $self->$method($thing);
        }

and then you just add 'handle_object', 'handle_hash',
'handle_scalar' etc. See Data::Visitor or Devel::PartialDump for an
example

-- 
  Yuval Kogman <[EMAIL PROTECTED]>
http://nothingmuch.woobling.org  0xEBD27418

_______________________________________________
Perl mailing list
[email protected]
http://perl.org.il/mailman/listinfo/perl

Reply via email to