Flame has asked for the wisdom of the Perl Monks concerning the following question:
I find myself faced with something I had never thought of before, now I only wonder if it can be done this way.
My goal is to be able to create a sub-ref with a stored argument, so that argument would be automatically first in the line of arguments whenever that sub-ref is executed. The following is something like what I have in mind:
my $code = \&mysub(10); sub mysub($@){ my $need = shift; my $have = 0; foreach (@_){ $have += $_; } if($need != $have){ return; } return 1; } if($code->(1,2,3,4)){ print "You had the correct number"; }
Now I realize that in that example it wasn't really necessary, but I think it illustrates what I'm looking for. Unfortunately I realize that this is probably a very unusual thing to want to do, so I anticipate that nothing like it will be possible, but one can hope :)
My thanks to those that reply.
My code doesn't have bugs, it just develops random features.
Flame ~ Lead Programmer: GMS | GMS
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: subref with stored argument?
by Paladin (Vicar) on Jan 10, 2003 at 00:30 UTC | |
|
Re: subref with stored argument?
by sauoq (Abbot) on Jan 10, 2003 at 01:09 UTC | |
by BrowserUk (Patriarch) on Jan 10, 2003 at 03:58 UTC | |
|
Re: subref with stored argument?
by dpuu (Chaplain) on Jan 10, 2003 at 00:32 UTC | |
by djantzen (Priest) on Jan 10, 2003 at 01:17 UTC | |
|
Re: subref with stored argument?
by particle (Vicar) on Jan 10, 2003 at 02:14 UTC |