PERL Help
Ok I made this PERL script and it was working flawlessly, untill today, of course near the time I was about to start using it. It's for a LAN Party registration and I made an array and told it to look through the array and if a predefined variable equals an array value then set another variable equal to < font c ...
Ok I made this PERL script and it was working flawlessly, untill today, of course near the time I was about to start using it. It's for a LAN Party registration and I made an array and told it to look through the array and if a predefined variable equals an array value then set another variable equal to < font color = ' gold ' > $alias. Well it worked but now isn't....everything else is working though. Here's the array part.
@specialpeeps = ("O.A.P.", "Blakflagg", "O.T.A.", "Smokin_Gunz", "Godiwill", "Pittdog", "ReggieReg", "Prophet", "Rapture", "Knight", "Antimatter", "shr1nk", "Ronin", "aeflux", "Apollo", "Mindphlux", "Renderer", "Paradox", "StevenKao", "Meadeiac", "Net$ushi", "GodCani", "The_Milkman", "RogueDawg", "Girl Injector", "nicad", "Oz|zY");
foreach $i (@specialpeeps) {
if ($alias eq "$i")
{
$name = "< font color = '#CCCC33' > $alias";
}else {
$name = "< font color = ' white' >$alias";
}
}
I can post the whole script if need be. This is really bothering me. It seems as if it just isn't parsing the array.
@specialpeeps = ("O.A.P.", "Blakflagg", "O.T.A.", "Smokin_Gunz", "Godiwill", "Pittdog", "ReggieReg", "Prophet", "Rapture", "Knight", "Antimatter", "shr1nk", "Ronin", "aeflux", "Apollo", "Mindphlux", "Renderer", "Paradox", "StevenKao", "Meadeiac", "Net$ushi", "GodCani", "The_Milkman", "RogueDawg", "Girl Injector", "nicad", "Oz|zY");
foreach $i (@specialpeeps) {
if ($alias eq "$i")
{
$name = "< font color = '#CCCC33' > $alias";
}else {
$name = "< font color = ' white' >$alias";
}
}
I can post the whole script if need be. This is really bothering me. It seems as if it just isn't parsing the array.
Participate on our website and join the conversation
This topic is archived. New comments cannot be posted and votes cannot be cast.
Responses to this topic
Here the fix
@specialpeeps = ("O.A.P.", "Blakflagg", "O.T.A.", "Smokin_Gunz", "Godiwill", "Pittdog", "ReggieReg", "Prophet", "Rapture", "Knight", "Antimatter", "shr1nk", "Ronin", "aeflux", "Apollo", "Mindphlux", "Renderer", "Paradox", "StevenKao", "Meadeiac", "Net$ushi", "GodCani", "The_Milkman", "RogueDawg", "Girl Injector", "nicad", "Oz|zY");
$found = "No";
foreach $i (@specialpeeps) {
if ($found eq "No") {
if ($alias eq "$i")
{
$name = " $alias";
$found = "Yes";
}else {
$name = "$alias";
}
}
}
@specialpeeps = ("O.A.P.", "Blakflagg", "O.T.A.", "Smokin_Gunz", "Godiwill", "Pittdog", "ReggieReg", "Prophet", "Rapture", "Knight", "Antimatter", "shr1nk", "Ronin", "aeflux", "Apollo", "Mindphlux", "Renderer", "Paradox", "StevenKao", "Meadeiac", "Net$ushi", "GodCani", "The_Milkman", "RogueDawg", "Girl Injector", "nicad", "Oz|zY");
$found = "No";
foreach $i (@specialpeeps) {
if ($found eq "No") {
if ($alias eq "$i")
{
$name = " $alias";
$found = "Yes";
}else {
$name = "$alias";
}
}
}
don't know if you care, but here's an explanation of your problem:
Your script would correctly set $name to use the right color when it found the correct name, BUT... it would then compare it against the next name, which it wouldn't match, so it changed back to white. Philipp wrote it so that it would only change the color if you didn't already find it. Another way to do it is to set it white first, then walk through the array:
@specialpeeps = ("O.A.P.", "Blakflagg", ...);
$name = "< font color = ' white' >$alias";
foreach $i (@specialpeeps) {
if ($alias eq "$i")
{
$name = "< font color = '#CCCC33' > $alias";
}
}
Not that Philipp's way is bad - in Perl, there are MANY different ways of accomplishing the same task. I just like this way better, because you end up do fewer assignments.
Your script would correctly set $name to use the right color when it found the correct name, BUT... it would then compare it against the next name, which it wouldn't match, so it changed back to white. Philipp wrote it so that it would only change the color if you didn't already find it. Another way to do it is to set it white first, then walk through the array:
@specialpeeps = ("O.A.P.", "Blakflagg", ...);
$name = "< font color = ' white' >$alias";
foreach $i (@specialpeeps) {
if ($alias eq "$i")
{
$name = "< font color = '#CCCC33' > $alias";
}
}
Not that Philipp's way is bad - in Perl, there are MANY different ways of accomplishing the same task. I just like this way better, because you end up do fewer assignments.
Why not use the pretty formatting that this message board has to offer ?
Code:
Code:
@specialpeeps = ("O.A.P.", "Blakflagg", "O.T.A.", "Smokin_Gunz", "Godiwill", "Pittdog", "ReggieReg","Prophet", "Rapture", "Knight", "Antimatter", "shr1nk", "Ronin", "aeflux", "Apollo","Mindphlux", "Renderer", "Paradox", "StevenKao", "Meadeiac", "Net$ushi", "GodCani","The_Milkman", "RogueDawg", "Girl Injector", "nicad", "Oz|zY"); $found = "No"; foreach $i (@specialpeeps) { if ($found eq "No") { if ($alias eq "$i") { $name = "< font color = '#CCCC33' > $alias"; $found = "Yes"; }else { $name = "< font color = ' white' >$alias"; } } }