plasmatwin
Programmer
ok I have the following subroutine in one of my programs, all it does is read a file and check various things then load it as a config. The subroutine isn't finished yet but this part of the syntax should be fine :-/
I have highlighted the parts that perl says are wrong in [red]red[/red] and I've put the error message at the bottom of this post.
and the error...
I have NO idea why these errors are here... I suspect it is because I am being an idiot and not spotting something but whatever... any help appreciated
I have highlighted the parts that perl says are wrong in [red]red[/red] and I've put the error message at the bottom of this post.
Code:
sub _rehash
{
print "Loading config...\n";
my $config="./battleserv.conf";
# check for config readability/existance
#if (!-r -e $config)
#{
# print "ERROR: Config file does not exist/is not readable\n";
# return "Failed to load config, please check the above for possible errors";
#}
# read the config file into an array and then close it
open(CONFIG, $config) or
{
print "ERROR: Could not open config file, config not loaded\n";
[red]return[/red] "Failed to load config, please check the above for possible errors";
}
my @config=<CONFIG>;
close(CONFIG);
# chomp those naughty naughty line breaks
chomp(@config);
my $seen_warning;
# first read through will check the config file by passing it into the hash "%check_config"
# and then seeing if required values are there aswell as checking sanity of other values
my %check_config;
my @check_channels;
foreach (@config)
{
(my $config, my $value) = split(/=/, $_, 2);
if ("$config" eq "channel")
{
# we put the channels into an array after sanitising them so that if everything passes
# without any critical errors we can just copy the array into the actual array
push(@check_channels, "$value");
}
else
{
# we will read these into a temp hash called %checkconfig this way we can perform
# sanity checks on every part of the hash
if ($check_config{$config}) {
$seen_warning = 1;
print "WARNING: repeat value of $config in config file (current value: $check_config{$config}), replacing with newest value ($value)\n";
}
$check_config{$config} = "$value";
}
}
if ($seen_warning)
{
print "Warnings were flagged in the config, while this still has produced a working config there is the possibility that the config will not perform the way you expect.\nIf the bot is not operating the way you expect then check the above for possible errors in your config.\n";
}
# clean the arrays out
undef %config;
undef @channels;
# since we have two nicely sanitised arrays we just have to copy them into the global arrays
@channels = @check_channels;
%config = %check_config;
print "Config loaded successfully\n";
[red]}[/red]
Code:
syntax error at C:\BattleServ\battleserv.pl line 66, near "return"
syntax error at C:\BattleServ\battleserv.pl line 111, near "}"
Execution of C:\BattleServ\battleserv.pl aborted due to compilation errors.
I have NO idea why these errors are here... I suspect it is because I am being an idiot and not spotting something but whatever... any help appreciated