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

Re: invoking subroutines

by ig (Vicar)
on Jul 01, 2011 at 07:19 UTC ( #912294=note: print w/ replies, xml ) Need Help??


in reply to invoking subroutines

the line $str->$str1($regexp); always passes $str as parameter to the subroutine.

$str is passed as first argument to the subroutine because you are using method invocation syntax. In particular, you are using the arrow operator: ->.

If you don't want $str passed as the first argument, you could use a symbolic reference:&{"${str}::${str1}"}($regexp).

use strict; use warnings; package XXX; sub YYY { my ($x) = @_; print "hi there $x\n"; } package main; my $str = 'XXX'; my $str1 = 'YYY'; { no strict "refs"; &{"${str}::${str1}"}(10); }


Comment on Re: invoking subroutines
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2015-07-02 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (37 votes), past polls