PDA

View Full Version : A better way to write this??


chasem
08-27-2015, 08:23 PM
I'm new to PERL and writing quests. Learned a ton just through everyones helpful posts here.

I'm wondering if there is a simpler way to write the following. It is for an NPC that will just be dealing with melee classes. It works, just guessing there is probably an easier way...

if($class eq 'Druid') { plugin::Whisper("Begone! I will not help a $class!"); return; } #No Druids return...
if($class eq 'Magician') { plugin::Whisper("Begone! I will not help a $class!"); return; } #No Mages return...
if($class eq 'Wizard') { plugin::Whisper("Begone! I will not help a $class!"); return; } #No Wizards return...
if($class eq 'Necromancer') { plugin::Whisper("Begone! I will not help a $class!"); return; } #No Necros return...
if($class eq 'Shaman') { plugin::Whisper("Begone! I will not help a $class!"); return; } #No Shaman return...
if($class eq 'Cleric') { plugin::Whisper("Begone! I will not help a $class!"); return; } #No Cleric return...
if($class eq 'Enchanter') { plugin::Whisper("Begone! I will not help a $class!"); return; } #No Enchanter return...

Thanks for any tips you can give.

Kingly_Krab
08-27-2015, 08:31 PM
Try this: if($class=~/Druid|Magician|Wizard|Necromancer|Shaman|Cleric|En chanter/i) {
plugin::Whisper("Begone! I will not help a $class!");
return;
}

chasem
08-27-2015, 08:38 PM
Awesome!! Thanks Kingly. Haven't come across the vertical bars used before.

Shendare
08-27-2015, 08:48 PM
The world is upside-down when a regular expression is actually the simplest way to do something. Hahaha!

Kingly_Krab
08-27-2015, 08:49 PM
The | is just an OR operator within REGEX.