Perl and packge

C

cvrèak

Hy,

Can somebody explain me when use *.pm files and when uses *.pl?

must be classes in *.pm files?
 
B

Bart Lateur

cvrèak said:
Can somebody explain me when use *.pm files and when uses *.pl?

Will this do?

http://perldoc.perl.org/perlmod.html


In short: there are two ways to specify files to load (require): the
special package syntax (Foo::Bar), and the plain (Unix) file path
format: "Foo/Bar.pm". The former is a special syntax that is recognized
as syntactic sugar for the latter, but only in source code. If you
specify the file as a string, or in a (scalar) variable, you *must* use
the file path format.

That's one way in which ".pm" special as a file extension. The second is
that with "use", Perl will treat Foo::Bar both as a file name (after
conversion), and as a package/class name, for which it will try to do a
"import" class method call. That's the main reason for which module
names and package names are commonly the same.
must be classes in *.pm files?

No.

Classes are defined as packages, and package declarations can be in any
type of source files. See above as to why package and file name are
usually the same. But it's not uncommon to have extra (utility) packages
in the same source file.
 

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,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top