i am using packages to break up a large piece of code into smaller pieces so it is easier to maintain.
------------ the following piece of code works :
-- this code loads the package #!/usr/bin/perl -w use strict ;
# call the packaged code require '/path/to/package/PackageName.pl' ; PackageName::SubName ();
# this is what the package looks like package PackageName ; use strict ;
sub SubName { print ("hello world \n" ) ; }
1 ;
------------
the following piece of code doesn't work :
-- this code loads the package #!/usr/bin/perl -w use strict ;
# call the packaged code require '/path/to/package/PackageName.pl' ; PackageName ;
# this is what the package looks like package PackageName ; use strict ;
# note that there is no subroutine in here print ("hello world \n" ) ;
1 ;
------------
the error message is : bareword "PackageName" not allowed while "strict subs" in use.
i guess my question is : do you have to have a subroutine in a package before it can be made to work? if not, how do you call a package that consists only of code without the use of a subroutine?
I'm not sure what you're trying to accomplish. If you are going to have no subroutines or variables defined for other packages to use, then what you're referring to is really a subscript(?). If that's the case you don't need a package declaration, and instead of require 'path/to/script.pl' you should use do 'path/to/script.pl'
However, you can have free code in a module. You would construct it in the same way as your second example, but leave out the reference to 'PackageName ;'
C<use> and C<require> basically invoke C<do> as part of their functionality. See `perldoc -f require` and `perldoc -f use` for example psuedo-code.
Randy.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>