Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Call sub with substiuted args

Reply
Thread Tools

Call sub with substiuted args

 
 
Rusty
Guest
Posts: n/a
 
      12-28-2003
Greetings,

My problem is I need to call a subroutine but the number of args can be
many and vary from call to call. What I'm trying to do is parse a
template and capture the data from the template into a scalar and then
call the subroutine with the scalar value and have perl substitute the
scalar with the data in the scalar and have that data interpreted
correctly. Here's some code to illustrate:

#!/usr/bin/perl

my $x = q/-values => {K1 => V1, K2 => V2}/;
mytestsub($x);
exit;

Now the above works, but not the way I hoped. It sees a simple scalar
sent to the subroutine. What I'm shooting for is this:

#!/usr/bin/perl

mytestsub(-values => {K1 => V1, K2 => V2, ...});
exit;

The snippet above the subroutine would see an array that contains a
scalar and a hash.

Has anyone had any success in doing this? I believe I can get type of
thing under tcl but that's not an option.

I can do this a couple other ways but I was hoping for this as it would
save me lots of pain

Thanks in advance for any tips.

Rusty

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      12-28-2003
Rusty wrote:
> What I'm shooting for is this:
>
> #!/usr/bin/perl
>
> mytestsub(-values => {K1 => V1, K2 => V2, ...});
> exit;
>
> The snippet above the subroutine would see an array that contains a
> scalar and a hash.


Sounds as if you want to pass a scalar and a hash reference to the sub.

my $scalar = '-values';
my $hashref = { K1 => 'V1', K2 => 'V2' };

mytestsub($scalar, $hashref);

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Death To Sub-Sub-Sub-Directories! Lawrence D'Oliveiro Java 92 05-20-2011 06:50 AM
Recognising Sub-Items and sub-sub items using xslt Ben XML 2 09-19-2007 09:35 AM
Is there a class or method to construct url args or extract url args? Ken Varn ASP .Net 2 06-22-2005 12:26 PM
args v. *args passed to: os.path.join() Pierre Fortin Python 2 09-18-2004 06:59 PM
When passing functions as args,how to pass extra args for passed function? python@sarcastic-horse.com Python 3 09-17-2003 12:25 AM



Advertisments