Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: Shorten scriptby l2kashe (Deacon) |
on Jul 22, 2003 at 19:07 UTC ( [id://276880]=note: print w/replies, xml ) | Need Help?? |
You could also use something along the lines of a dispatch table.
In this case the %match is a little useless, as your blocks aren't really doing anything all that different aside from what to print. You are also using variables in the block that aren't being created in the block so its difficult to grasp exactly what you are trying to shorten. In a more complex case, the value of $match{pattern} could be a code ref, or any other data structure which could shorten the main loop a touch.. Something like
In my own code, I tend to either make $results either an array or hash reference, depending on the situation, and the call may be altered to be say push(@$results, &$func($1)); or some such. HTH, regards use perl;
In Section
Seekers of Perl Wisdom
|
|