Richard Heintze wrote:
I'm using these statements in my main program:
use DisplayPCE qw($order $fnx );
... print join("", map { qq[<td>$_</td>] } @{$DisplayPCE::order}); ...
When I use the debugger, I find that order is undefined! When I use the browser to view the page, the value of undef is confirmed.
When I abandon packages and put the definition of order in the main program, it works!
Can anyone help me understand why my package is not working? Siegfried
Here is the contents DisplayPCE.pm:
package DisplayPCE; our @EXPORT = qw($order ); my $order = ["First Name", "Last Name", "E-Mail", "User Name", "Address", "City", "State", "Zip Code", "Country", "Phone", "Org.", "Gender", "Ethnicity", "Age", "Religious Affiliation" ];
1;
@EXPORT isn't a Perl standard variable, it is just a convention provided by the standard Exporter module. So you will need to let Perl know that your package is an exporter and then it will automatically export what is in @EXPORT, you may want to consider using @EXPORT_OK instead.
package DisplayPCE; require Exporter; @ISA = qw( Exporter );
Using Exporter and putting vars in @EXPORT_OK is the *right way*, but... note that using 'my' creates a lexical variable. No matter which way you do it you need to use package variables in order for them to be seen outside the package. You can use either:
use vars qw($order);
-or-
our $order;
to create package variables. Then you can access them from another package by using the fully qualified name:
use Data::Dumper; print Dumper($DisplayPCE::order);
If you want to access the variable without the fully qualified name, you'll need to use Exporter as already described.
Randy.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>