in reply to What is the significance of a package
One important feature is that packages give you namespaces. Entries with identical names can co-exist because they live in different namespaces. As to demonstrate:
### my-perl-script.pl use strict; use warnings; use Bar; use subs qw(foo); foo; sub foo { print "Foo, from the main package.\n"; }
### Bar.pm package Bar; use strict; use warnings; sub foo { print "Also foo, but this comes from the Bar package.\n"; print "(And no, if my wife calls, I'm not at the bar!)\n"; }
Try to do this without packages, and Perl will rightfully complain, "Subroutine foo redefined at ...". Which is hardly ever what you want.
|
---|
In Section
Seekers of Perl Wisdom