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
####
#!/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";
}
####
Name "main::cstrike" used only once: possible typo at ./loadmap.pl line 12 (#1)
(W once) Typographical errors often show up as unique variable names.
If you had a good reason for having a unique name, then just mention 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 MAP.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