Re: about dispatch tables

2010-05-06 Thread Harry Putnam
Shlomi Fish writes: > Hi Harry, > > thanks for replying inline (bottom posting). > > On Thursday 06 May 2010 16:19:32 Harry Putnam wrote: >> Shlomi Fish writes: >> >> >> [...] >> >> > sub dispatch >> > { >> > >> >my ($method, @rest_of_args) = @_; >> >> Not sure what $method is supposed

Re: about dispatch tables

2010-05-06 Thread Shlomi Fish
Hi Harry, thanks for replying inline (bottom posting). On Thursday 06 May 2010 16:19:32 Harry Putnam wrote: > Shlomi Fish writes: > > > [...] > > > sub dispatch > > { > > > > my ($method, @rest_of_args) = @_; > > Not sure what $method is supposed to be doing. > Sorry, I'm usually used

Re: about dispatch tables

2010-05-06 Thread Harry Putnam
Shlomi Fish writes: [...] > sub dispatch > { > my ($method, @rest_of_args) = @_; Not sure what $method is supposed to be doing. > my %dispatch = > ( > 'N' => sub { return N_func(@rest_of_args); }, > 'L' => sub { return L_func(@rest_of_args); }, >

Re: about dispatch tables

2010-05-06 Thread Harry Putnam
Harry Putnam writes: Egad... I'm messing up what I want to say way too much. There is an unfortunate type in there... > But after finally reading your comments.. I'm thinking to stick with > something more like this pattern. > > , > | @ar ## already with data inside (global) > | > | sub

Re: about dispatch tables

2010-05-06 Thread Harry Putnam
Akhthar Parvez K writes: > Why are you calling the subroutine N? Have you already defined a > subroutine with the name N in your program? Yes, it was already defined... and I see now how I was nesting a second call in there... not really what was needed or intended. thanks. -- To unsubscri

Re: AW: about dispatch tables

2010-05-06 Thread Harry Putnam
Thomas Bätzler writes: >> sub func { %h = ( N => sub { print N(@_) . "\n"; } ); } > > If you call the sub like this, it'll create the hash %h containing the > key "N" associated with a code reference to an anonymous > subroutine. When that subroutine is called it will pass its _current_ > argumen

Re: about dispatch tables

2010-05-06 Thread Shlomi Fish
On Thursday 06 May 2010 13:24:10 Harry Putnam wrote: > Philip Potter writes: > > On 5 May 2010 17:29, Harry Putnam wrote: > >> Anyway, I understood he was saying NOT global. > >> > >> What I asked is why that would matter. That is, the values or > >> elements in @_ arrive inside the `sub dispt

Re: about dispatch tables

2010-05-06 Thread Harry Putnam
Harry Putnam writes: > . . . . ... I'm still not seeing why the > values in @_ are not available at the call to N() inside like this: > (incomplete code) Disregard above. Sorry about the line noise... I missed the main part of Phillips' explanation -- To unsubscribe, e-mail: beginners

Re: about dispatch tables

2010-05-06 Thread Harry Putnam
Philip Potter writes: > On 5 May 2010 17:29, Harry Putnam wrote: >> Anyway, I understood he was saying NOT global. >> >> What I asked is why that would matter.  That is, the values or >> elements in @_ arrive inside the `sub dispt {...}', so should be >> available to anything inside `sub dispt {

Re: about dispatch tables

2010-05-06 Thread Akhthar Parvez K
On Wednesday 05 May 2010, Harry Putnam wrote: > But even though I can work with that... I'm still not seeing why the > values in @_ are not available at the call to N() inside like this: > (incomplete code) > > func($val1,$val2); > > sub func { %h = ( N => sub { print N(@_#HERE) . "\n"; } ); }

AW: about dispatch tables

2010-05-05 Thread Thomas Bätzler
Harry Putnam asked: > But even though I can work with that... I'm still not seeing why the > values in @_ are not available at the call to N() inside like this: > (incomplete code) > > func($val1,$val2); > > sub func { %h = ( N => sub { print N(@_) . "\n"; } ); } If you call the sub like this,

Re: about dispatch tables

2010-05-05 Thread Harry Putnam
"Uri Guttman" writes: >> "HP" == Harry Putnam writes: > > HP> A third sub function is called in the dispatch table ( N(@_); ) but > HP> the variables don't survive to be use there. > > there are no variables to survive in a sub, just passed arguments in @_ > > HP> The output from the s

Re: about dispatch tables

2010-05-05 Thread Philip Potter
On 5 May 2010 17:29, Harry Putnam wrote: > Anyway, I understood he was saying NOT global. > > What I asked is why that would matter.  That is, the values or > elements in @_ arrive inside the `sub dispt {...}', so should be > available to anything inside `sub dispt {...}'  right? > > And `%hash =

Re: AW: about dispatch tables

2010-05-05 Thread Harry Putnam
Thomas Bätzler writes: > Harry Putnam asked: > [...] >> which is also inside sub dispt {the sub function}. Where does global >> come in? > > Hint: $code->(@_); Yes, I knew it could be done there... but what to do then when more function calls are added. Are you thinking something like: i

Re: about dispatch tables

2010-05-05 Thread Harry Putnam
Philip Potter writes: > On 5 May 2010 14:36, Harry Putnam wrote: >> "Uri Guttman" writes: >> >>>   HP> The output from the script below: >>>   HP> Shows 6 elements arrive in dispt($g, @ar) as @_.  But when sub N(@_) >>>   HP> is called, no variables arrive there. @_ is empty. When it seems like

Re: about dispatch tables

2010-05-05 Thread Philip Potter
On 5 May 2010 15:26, Thomas Bätzler wrote: > Harry Putnam asked: > [...] >> which is also inside sub dispt {the sub function}.  Where does global >> come in? > > Hint: $code->(@_); Or indeed &$code; if you want to be cryptic :) Phil -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For

Re: about dispatch tables

2010-05-05 Thread Philip Potter
On 5 May 2010 14:36, Harry Putnam wrote: > "Uri Guttman" writes: > >>   HP> The output from the script below: >>   HP> Shows 6 elements arrive in dispt($g, @ar) as @_.  But when sub N(@_) >>   HP> is called, no variables arrive there. @_ is empty. When it seems like >>   HP> 5 elements should hav

AW: about dispatch tables

2010-05-05 Thread Thomas Bätzler
Harry Putnam asked: [...] > which is also inside sub dispt {the sub function}. Where does global > come in? Hint: $code->(@_); HTH, Thomas -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: about dispatch tables

2010-05-05 Thread Harry Putnam
"Uri Guttman" writes: > HP> The output from the script below: > HP> Shows 6 elements arrive in dispt($g, @ar) as @_. But when sub N(@_) > HP> is called, no variables arrive there. @_ is empty. When it seems like > HP> 5 elements should have arrived there > > well, it helps if you actuall

Re: about dispatch tables

2010-05-04 Thread Uri Guttman
> "HP" == Harry Putnam writes: HP> A third sub function is called in the dispatch table ( N(@_); ) but HP> the variables don't survive to be use there. there are no variables to survive in a sub, just passed arguments in @_ HP> The output from the script below: HP> Shows 6 elements

Re: about dispatch tables

2010-05-04 Thread Harry Putnam
A mock up of dispatch table. No dispatching done here... only a test of passing values. What am running into here? one sub function called (dispt('hello',@ar); ) containing a dispatch table. A third sub function is called in the dispatch table ( N(@_); ) but the variables don't survive to be use

Re: about dispatch tables

2010-04-30 Thread Harry Putnam
Steve Bertrand writes: > First note that this will run forever :) Yup... for a second there I thought I'd inadvertently pressed `y' at the linux prompt... > Also, there's no proper conditional logic involved here, the dispatch > table subs are just calling back to other subs from within the di

Re: about dispatch tables

2010-04-29 Thread Steve Bertrand
On 2010.04.28 22:04, Harry Putnam wrote: > Your reference to `call back' is probably just the ticket... but I > will show actual code that tries to do what I need, and maybe you can > show how a `call back would work. This is pretty simple and has no inherent complexity whatsoever, but hopefully

Re: about dispatch tables

2010-04-28 Thread Harry Putnam
Steve Bertrand writes: First off let me thank you for the time and effort involved in replying. > On 2010.04.26 15:24, Harry Putnam wrote: > >> I want to try to describe briefly what problem I'm having. >> But not show any working code. > > That's ok, but it isn't clear to me that you have reall

Re: about dispatch tables

2010-04-28 Thread Steve Bertrand
On 2010.04.26 15:24, Harry Putnam wrote: > I hope some of you will go along with this approach. > > I want to try to describe briefly what problem I'm having. > But not show any working code. > > I've made so much of a mess trying a lot of different things I'd like > to have some idea that at lea

Re: about dispatch tables

2010-04-27 Thread Steve Bertrand
On 2010.04.26 15:24, Harry Putnam wrote: > I hope some of you will go along with this approach. > > I want to try to describe briefly what problem I'm having. > But not show any working code. > > I've made so much of a mess trying a lot of different things I'd like > to have some idea that at lea

Re: about dispatch tables

2010-04-27 Thread Steve Bertrand
On 2010.04.26 15:24, Harry Putnam wrote: > I want to try to describe briefly what problem I'm having. > But not show any working code. That's ok, but it isn't clear to me that you have really described a problem that you are stuck on. > I guess where I get stuck is how to make a dispatch table w

about dispatch tables

2010-04-26 Thread Harry Putnam
I hope some of you will go along with this approach. I want to try to describe briefly what problem I'm having. But not show any working code. I've made so much of a mess trying a lot of different things I'd like to have some idea that at least theoretically I'm on the right track (or wrong track

Re: about dispatch tables

2010-04-24 Thread Harry Putnam
Shawn H Corey writes: > Harry Putnam wrote: >> Harry Putnam writes: >> >>> However, using your suggestion: >>> > $code->($var1, $var2); >> >> Something I forgot to ask about that. >> >> What if more than 1 of referenced sub routines needed vars passed in >> but the needed vars were not the sam

Re: about dispatch tables

2010-04-24 Thread Harry Putnam
Ireneusz Pluta writes: > Harry Putnam wrote: >> I don't see the expected result when I press `y'. > you never print it errr... yup, (corrective action taken). -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.

Re: about dispatch tables

2010-04-24 Thread Ireneusz Pluta
Harry Putnam wrote: I don't see the expected result when I press `y'. you never print it (The code is at the end) It seems to do nothing. ... non working code: #!/usr/local/bin/perl use strict; use warnings; my $var1 = 'whoopdee'; my $var2 = 'do'; my %dispatch = ( y => \&yy,

Re: about dispatch tables

2010-04-24 Thread Peter Scott
On Sat, 24 Apr 2010 10:06:37 -0500, Harry Putnam wrote: > Harry Putnam writes: > > >> However, using your suggestion: >> > $code->($var1, $var2); > > Something I forgot to ask about that. > > What if more than 1 of referenced sub routines needed vars passed in but > the needed vars were not

Re: about dispatch tables

2010-04-24 Thread Shawn H Corey
Harry Putnam wrote: Harry Putnam writes: However, using your suggestion: > $code->($var1, $var2); Something I forgot to ask about that. What if more than 1 of referenced sub routines needed vars passed in but the needed vars were not the same? I'm guessing that using $code->() is not suc

Re: about dispatch tables

2010-04-24 Thread Harry Putnam
Harry Putnam writes: > > However, using your suggestion: > > $code->($var1, $var2); Something I forgot to ask about that. What if more than 1 of referenced sub routines needed vars passed in but the needed vars were not the same? I'm guessing that using $code->() is not such a good idea. Wh

Re: about dispatch tables

2010-04-24 Thread Shawn H Corey
Harry Putnam wrote: Ireneusz Pluta writes: Harry Putnam wrote: #!/usr/local/bin/perl use strict; use warnings; my $var1 = 'whoopdee'; my $var2 = 'do'; my %dispatch = ( y => \&yy($var1,$var2), this, actually, is not a code reference but a return value reference of the &yy($var1,

Re: about dispatch tables

2010-04-24 Thread Harry Putnam
Ireneusz Pluta writes: > Harry Putnam wrote: >> #!/usr/local/bin/perl >> >> use strict; >> use warnings; >> >> my $var1 = 'whoopdee'; >> my $var2 = 'do'; >> >> my %dispatch = ( >> y => \&yy($var1,$var2), > this, actually, is not a code reference but a return value reference > of the &yy(

Re: about dispatch tables

2010-04-24 Thread Ireneusz Pluta
Harry Putnam wrote: #!/usr/local/bin/perl use strict; use warnings; my $var1 = 'whoopdee'; my $var2 = 'do'; my %dispatch = ( y => \&yy($var1,$var2), this, actually, is not a code reference but a return value reference of the &yy($var1, $var2) subroutine call, executed right at the tim

about dispatch tables

2010-04-23 Thread Harry Putnam
A while ago I asked for an example of a dispatch table. r...@i.frys.com was kind enough to post the example below. After tinkering with it a while I think I got it working ok, but I wondered when you are using the reference syntax \&... How do you pass in variables? My test script posted below t