Don't ask to ask, just ask | |
PerlMonks |
Re: Trying to streamline repetitive code....by kyle (Abbot) |
on Oct 29, 2009 at 03:26 UTC ( [id://803867]=note: print w/replies, xml ) | Need Help?? |
That's quite a Wall of Text. I'm guessing this doesn't run under strict. Anyway, I wrote this just for fun:
The m8_text() sub returns the text from your node verbatim. I do a few replacements on it, and I confirm before and after that it compiles with eval. So you can paste the results into a sub like this:
Call the sub like node_803848( $big_m{$name}, $name ) with $name set to "M8", for example. At that point, you need %big_m to have a hash ref for each of your M1–M8, and each of those hashes has an entry for each *M8* variable in the original. There appear to be no hashes in there, so it's all scalars and arrays that you could initialize like so:
Of course, I haven't tried to run this, but if it works, the result could run under strict with a few more changes. Each use of foreach needs a my. There are places where "M8" appears in string literals, and that needs to be $name. If I had this in front of me, I'd be strongly tempted to rewrite it all, but I don't have time for that here and now. Instead, I wrote the cheap and evil solution you see above. I don't actually recommend it, but it might get you started. Good luck.
In Section
Seekers of Perl Wisdom
|
|