I am writing a perl module that, when supplied a the name of a game, locates the map directory and creates an array with the map names for that specific game. I am getting several errors that are unclear to me. Here is the module.
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
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.
#!/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"; }
And here are the errors I receieve from running loadmap.pl
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
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.

In reply to Perl Module Problems by davidov0009

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.