Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
cleaning up code with "do" ?by schweini (Friar) |
on Aug 18, 2004 at 21:50 UTC ( [id://384124]=perlquestion: print w/replies, xml ) | Need Help?? |
schweini has asked for the wisdom of the Perl Monks concerning the following question:
hi, oh ye enlightened ones that absorb the light of knowledge, i've got this big messy perlTk program that i did. I'm trying to clean it up just a little, just to make my head spin a little bit less. i figured that i'd simply cut 'n paste the "core" functions into a seperate file, and include that file in the main program using "do". of course i *should* use "use" or "require", but since i'm doing some quite messy namespace-stuff (plugins, global dbh's, eval-ed strings that call subs, etc.), that would be a major pain in the behind. so, after doing all this, the main program doesn't quite work as expected - Tk's WaitVariable() and some other stuff "kind of" work, but overall, the program just doesn't function exactly the same way it used to. now, in the docs for "do" it says that:
which seems to me, is the only major difference to a eval `cat file.pl`, but i don't quite understand what that means, or how it could affect monster-modules like Tk soooooo: what is the best way to simply "include" a file, so that the including program exactly(!) functions as if as if the code contained in that file would be 'inline'? thanks, - schweini Update: i tried eval `type file.pl`, and it gives me the same problems as 'do' Update2: e.g. i tie() a Tk::Text widget to a file-handle like this: tie(*INVOICEVIEW, 'Tk::Text', $invoiceView); and, after the "cut 'n paste", the line
in the 'main' file gives me the error
(although it worked as expected before the cut 'n paste. sigh.) Update3: plesae note that i'm not simply trying to include a config-file or something. i have to include a whole lotta subs and all. Edit by tye, replace PRE with CODE
Back to
Seekers of Perl Wisdom
|
|