This module is saved as MAP.pm in the same directory as the script below that calls it. Here is the script (saved as loadmap.pl) to check if the array has been created.package MAP; use diagnostics; use strict; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = qw(array); # Create Map Array given an argument. sub array { # Declare Variables my $game = @_; my $user = $ENV{'USER'}; # Create Dir Path my $dir = "/home/$user/hlds_l/$game/maps/"; #Read maps from directory if (-d $dir) { opendir(MAPS, $dir) || die("Cannot open directory"); @$game= readdir(MAPS); closedir(MAPS); # Take only maps and trim .bsp @$game=grep /\.bsp/, @$game; my $map; foreach $map (@$game) { $map=~ s/\.bsp// } } return (@$game); } 1; # end
And here are the errors I receieve from running loadmap.pl#!/usr/bin/perl5 -w use diagnostics; # Load Module use MAP; # Call Routine MAP::array("cstrike"); # Print returned array my $map; foreach $map (@cstrike) { print "$map\n"; }
If I disable strict and diagnostics and -w in both the script and the pm I receive no ouput at all. I am not using an array reference, I am passing the arg cstrike to the sub array in order to create an array for game cstrike. Any help appreciated.Name "main::cstrike" used only once: possible typo at ./loadmap.pl lin +e 12 (#1) (W once) Typographical errors often show up as unique variable nam +es. If you had a good reason for having a unique name, then just menti +on it again somehow to suppress the message. The our declaration is provided for this purpose. Can't use string ("1") as an ARRAY ref while "strict refs" in use at M +AP.pm line 39 (#2) (F) Only hard references are allowed by "strict refs". Symbolic references are disallowed. See perlref. Uncaught exception from user code: Can't use string ("1") as an ARRAY ref while "strict refs" in +use at MAP.pm line 39. MAP::array('cstrike') called at ./loadmap.pl line 9
In reply to Perl Module Problems by davidov0009
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |