Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Example... ( Re: Interpolating variables for use in method calls )

by lestrrat (Deacon)
on Jul 14, 2001 at 02:31 UTC ( [id://96614]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
        my $subname = 'baz';
        my $param   = { abc => 'xyz' }; # or an object. whatever.
    
        eval 'foo->' . "$subname( \$param )";
    
  2. or download this
        # first, the string that is to be eval'ed is created
        'foo->' . "$subname( \$param )"  => 'foo->baz( $param )'
    ...
        foo->baz( $param );
    
        # where $param is the ref to a hash
    
  3. or download this
        # suppose we use "$subname( $param )"
        'foo->' . "$subname( $param )" => "foo->baz( 'HASHx(....)' )"
    ...
        # so no interpolation is done in the first step...
        foo->$subname( $param ); # ah, but this is perfectly valid!
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found