How can I make this work? The variable in the required printit.pl file doesn't contain anything. It would end up printing "Today is" and thats it.

-------------------------------------------------- This is the contents of the main perl script file: -------------------------------------------------- #!/usr/bin/perl5 -wT use strict; require '/usr/local/www/cgi-bin/printit.pl';

my $text = "friday!"; &print_text; exit;

-------------------------------------------------- This is the contents of the printit.pl file: --------------------------------------------------

If you're using -w then you should have seen you're trying to use an uninitialzed value. ie: $text in printit.pl needs a value. Initialize $text in your print_text routine; ie: my $text = $_[0]; - or - my $text = shift; - and pass the variable when you call print_text; ie: &print_text( $text );

You might like to have a think about writing modules instead of those old fashioned libraries.

package Printit; # package all the following functions and variables into the Printit namespace. use strict;

sub new{ # The new method is the class constructor. my( $class, %params ) = @_; bless { %params }, $class; # Bless a reference to an anonymous hash into the Printit class. The address that this reference points to is the object of our endeavours. }

sub printit{ my( $class, %params ) = @_; print "Today is $params{'text'}\n"; $class->new( %params ); # Hand a hash which holds the goods off to the new method for blessing. (Actually, you don't need this if you're printing from this method). }

1;

This is a very simple example. It uses a hash because I think they're the most flexible, and are easier to read as your program grows. Learning Perl and Programming Perl are two excellent books which cover this subject. I should also mention that values are usually returned to your program; ie:

If you want to use variables in other "required" files of your program aswell, use the vars pragma. use strict doesn't allow you just using a variable. You'll have to tell where it is stored. When using my(), the variable doesn't get stored in the symbol table, which is efficient. However, that automatically makes the variable unusable through your entire program.

Ah! I like that method. Is it any less secure to "use vars" than to do it the first way or making a .pm? I could really use this for a couple of my programs where I just need to have a remote file that has a list of set variables in it. (and a 1; as well )

It just depends on what you want to do with your program. At least, you have the settings separated from the programming code, which is a good thing.

For a simple program, my use vars method would be good enough. It just creates new symbol entries in the package namespace, which can be used globally in that package (often main)

However, when you're using 50 variables, you might want to use a different approach. That also requires good development. I don't know any trick that just solves such bug problem.

The .pm method actually does some Object Orientated programming trick. OOp is a very very very cool way of programming, if you're deep in it and understand the use of it.. Otherwise, I believe it's just confusing....althrough some people think different about this.