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:
... It also differs in that code evaluated with "do FILENAME" cannot see lexicals in the enclosing scope ...

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
print INVOICEVIEW translate("[ Factura vacia ]")."\n";

in the 'main' file gives me the error
Can't locate object method "INVOICEVIEW" via package "translate" (perhaps you forgot to load "translate"?) at C:\wwwroot\protopos\protopos4.pl line 773.

(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


In reply to cleaning up code with "do" ? by schweini

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.