in reply to Re: Re: How to pass a variable to function selected from a hash
in thread How to pass a variable to function selected from a hash
Using shift to handle fixed arguments is a standard idiom in Perl. It sometimes not the clearest way to express yourself, but avoiding is not always better either. Use it when it fits. Sometimes that is a matter of taste. In this case I would use it.
For more on what bit you, see Arrays are not lists.
For your actual problem you may be glad to find out that there is no need to actually name your handler functions. Just use sub to declare them. When combined with closures (as explained in perlref) this leads to some powerful programming techniques which are as different from standard procedural and OO programing as they are from each other. For more on that I recommend some of my posts that touch on functional techniques (a couple of which are on my home node) and visiting MJD's site and looking around.
UPDATE
I would just like to mention that the way to first encounter
functional programming is not how I did it. I was told
to find out why a several-hundred line program was slow.
I spent a good chunk of a day reading something written by
a tired programmer in a hurry. When I finally
figuring out that a key step was the line that read:
I was far from pleased. And even though I have since learned to like the technique and use it, I make sure that anyone who will have to read my code gets a much gentler introduction to how it works. :-)print join ",", map { &{$field_info{$_}{format}}($deal) } @fields;
BTW I was successful in speeding the program up. In fact there is a significant performance mistake in the above line. Given that $deal is a data structure and we are looping over a set of deals, what improvement can you find?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re (tilly) 3: How to pass a variable to function selected from a hash
by dkubb (Deacon) on Jan 18, 2001 at 12:51 UTC | |
by tilly (Archbishop) on Jan 18, 2001 at 13:10 UTC |