Found a way to write modules without package, export

G

Great Deals

First, copy and paste all subs into a file named something.pm then add
1; to the end of something.pm
No need of export or package
Isn't that great? Why would people even use package/export?

In main program something.pl, write use something

something.pm:
sub getit2{
return time;
}

1;

something.pl:
#!/usr/bin/perl -w
use something;

$ab= getit2;
print "$ab\n";
 
A

Anno Siegel

Great Deals said:
First, copy and paste all subs into a file named something.pm then add
1; to the end of something.pm
No need of export or package

What made you think you need "package", or Exporter.pm, to put subs into
another file? Of course you can do that. The result is not a Perl module,
however. That part of your subject is wrong.
Isn't that great? Why would people even use package/export?

Go ahead and use it for a while. You'll discover the advantages of
name spaces and their separation quite on your own.

[code snipped]

Anno
 
P

peter pilsl

Great said:
Isn't that great? Why would people even use package/export?

modules grant you some kind of privacy for the code you put into this
module. You can easily split up big projects into several modules without
having to fear namespace-collisions. This will get even more important if
you want to offer your module to various applications/authors and use
OO-approaches.

You just split your code into several files, but dont split the underlying
structure.

peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top