I am trying to apply some Software Engineering code management to what is becoming a very large hunk of code. I am trying to break this down into functional "hunks" of no more than 100 line or so. The code would still be co-operating and using global data from main.
"Perl does not patrol private/public borders within its modules--...." Programming Perl 2nd Ed. Pg 287.
This code is a minimalist example of my problem. The global data in 'main' is coming up undefined when read from the package.
use strict;
require "pit.pm"; ## also use or require w/o quotes
my $Email="abc\@example.com";
print "1) $Email\n";
pit::printIT();
print "1) $Email\n";
print "1) done\n";
#use pit; ## doesn't work here either
Here is the pit.pm
package pit;
sub printIT {
my $xyzzy = $main::Email;
print "2) #xyzzy\n";
}
1;
Running gives:
wf13[~]>perl testGlobal.pl
1) abc@example.com
2)
1) abc@example.com
1) done
What do I have to do in main to let other packages read my $main::Email variables?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.