Training, Open Source computer languages

PerlPythonMySQLTclRubyC & C++LuaJavaTomcatPHPhttpdLinux

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Packages in packages in Perl

In perl, all your variables (except "my" ones, which we'll leave for another day) are arranged into packages, and by default that's a package called "main". So if you write about a scalar called $jeremy, that's really $main::jeremy and if you write about a named block of code called &mary, that's really &main::mary.

Why?

So that, as your programs grow, you can arrange all the variables and pieces of code into their own uniquely named modules. That then allows you to use the same name several times over without a conflict.

Good news - but it doesn't go far enough so far; what I've described only goes one level further and module files (for example) would all end up in a single massive "pancake" directory. So the :: notation can be nested, and package namespaces can be nested within package namespaces. As far as file organisation is concerned, you'll be working with a directory structure. This sort of thing is very much used on the CPAN, from where you can download modules such as Net::FTP - to be found once installed in a file called FTP.pm in the Net directory.

Here's an example program and some modules that show this in action.

$ perl pk2lev
tutor
designer
beauty therapist
$

And the pk2lev program:

use ellis::graham;
use ellis::lisa;
use whelan::lisa;
print ellis::graham::job();
print ellis::lisa::job();
print whelan::lisa::job();

The directory structure:

$ ls ellis whelan pk2lev
pk2lev

ellis:
graham.pm lisa.pm

whelan:
lisa.pm
$

And a sample module file:

$ cat ellis/lisa.pm

package ellis::lisa;
sub job {
return "designer\n";
}

1;
$
(written 2005-12-16 20:40:31)

 
Associated topics are indexed under
P209 - Subroutines in Perl
P218 - Perl - More Objects
P616 - Perl - FTP and Telnet Modules

Back to
Perl course during the week, getting married at the weekend
Previous and next
or
Horse's mouth home
Forward to
Copyright - how much can I legally copy?
Some other Articles
MySQL permissions and privileges
Design - one name, one action
Bigger Box Campaign
Copyright - how much can I legally copy?
Packages in packages in Perl
Perl course during the week, getting married at the weekend
Halal in Melksham
Getting favicon to work - avoiding common pitfalls
Greater Western Franchise Awarded
Apache httpd - serving web documents from different directories
1892 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

© WELL HOUSE CONSULTANTS LTD., 2008: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 0800 043 8225 or 01225 708225 • FAX: 0845 8382 405 or 01225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho