I'm sure you'd all get bored if I stopped posting my Perl troubles 
Here's a snippet of code I have which is plaguing me.
I am parsing a log file line by line, the first input works, the second does not work as I had hoped.
It seems it should be obvious...
Input:
[Mon May 13 20:05:51 2002] [58 Myrmidon] Oreck (Barbarian) <Dread Templar> ZONE: emeraldjungle
[Mon May 13 18:26:22 2002] [58 Myrmidon] Oreck (Barbarian) <Dread Templar>
Output:
Oreck,58,Warrior,Barbarian,emeraldjungle,Mon May 13 20:05:51 2002
Oreck,Oreck,,,,Mon May 13 18:26:22 2002
Code:
if ($line =~ m/Dread Templar/)
{
$line =~ m/^\[([\w\d\s]*:.*)\] \[.*/;
$date = $1;
$line =~ m/^\[.*\] \[.*\] ([A-Z,a-z,0-9]+) /;
$name = $1;
if ($line =~ m/^\[.*\] \[ANONYMOUS\] .*/)
{
print OUT "$name,Anonymous,Anonymous,Anonymous,Anonymous,$date";
}
else
{
$line =~ m/^\[[\w\d\s]*:.*\] \[([\d]+) (\w+)\] \w+ \(([\w\s]+)\) <.*>\s*ZONE:\s*([a-z]+)/;
$number = $1;
$title = $2;
$class = $3;
$zone = $4;
}
print OUT "$name,$number,$title,$class,$zone,$date";
}
print OUT "\n";
}
}
Here's a snippet of code I have which is plaguing me.
I am parsing a log file line by line, the first input works, the second does not work as I had hoped.
It seems it should be obvious...
Input:
[Mon May 13 20:05:51 2002] [58 Myrmidon] Oreck (Barbarian) <Dread Templar> ZONE: emeraldjungle
[Mon May 13 18:26:22 2002] [58 Myrmidon] Oreck (Barbarian) <Dread Templar>
Output:
Oreck,58,Warrior,Barbarian,emeraldjungle,Mon May 13 20:05:51 2002
Oreck,Oreck,,,,Mon May 13 18:26:22 2002
Code:
if ($line =~ m/Dread Templar/)
{
$line =~ m/^\[([\w\d\s]*:.*)\] \[.*/;
$date = $1;
$line =~ m/^\[.*\] \[.*\] ([A-Z,a-z,0-9]+) /;
$name = $1;
if ($line =~ m/^\[.*\] \[ANONYMOUS\] .*/)
{
print OUT "$name,Anonymous,Anonymous,Anonymous,Anonymous,$date";
}
else
{
$line =~ m/^\[[\w\d\s]*:.*\] \[([\d]+) (\w+)\] \w+ \(([\w\s]+)\) <.*>\s*ZONE:\s*([a-z]+)/;
$number = $1;
$title = $2;
$class = $3;
$zone = $4;
}
print OUT "$name,$number,$title,$class,$zone,$date";
}
print OUT "\n";
}
}