Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: $var as accessor name?

by broquaint (Abbot)
on Mar 11, 2004 at 15:04 UTC ( [id://335830]=note: print w/replies, xml ) Need Help??


in reply to $var as accessor name?

You could always just extend Proc::ProcessTable e.g
sub match { my($self, @matches) = @_; my @fields = $self->fields; my @ret; for my $p (@{ $self->table }) { push @ret => { map {; $_ => $p->$_ } @fields } if grep { my $val = $_; grep { $p->$_ =~ $val } @fields } @matches; } return @ret; }
That will return a list of hashes, each containing the information for each process where one of the fields matched one of the match values.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: $var as accessor name?
by matija (Priest) on Mar 11, 2004 at 20:14 UTC
    Thank you, everybody, for pointing out my blind spot.

    I guess when you're wondering if Perl can do something, you should try it first, because usualy it does :-)

    Special thanks to broquaint for this lovely code.

      If the method name is a variable, it does have to be a simple scalar (e.g. $obj->$hash{method_foo} won't work).

        That's not strictly true, though it is messy.

        { package test; sub new{ return bless [], $_[0]; } sub meth1{ print 'meth1'; } }; $t=test->new; $t->meth1; meth1 $h{x}='meth1'; $t->${ \$h{x} }; meth1

        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://335830]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-26 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found