Welcome to the Monastery | |
PerlMonks |
Re^3: If statement not workingby Marshall (Canon) |
on Aug 26, 2012 at 01:17 UTC ( [id://989767]=note: print w/replies, xml ) | Need Help?? |
I see what you mean, that this is a "dangling else" clause. I guess something like: would have worked although the hash based solutions in this thread are probably more efficient. BTW, I have no problem with this trailing "if" syntax in a situation like this were the intent and readability is very clear. The "why" question wasn't asked. However since Perl is so good at processing strings, I would suggest that translating an easily understandable string into a shorter more cryptic string is usually just not necessary or advisable. I would not do this translation without a good reason. One reason might be that this program talks to something else that only understands the two letter abbreviations, however in that case, the default of not abbreviating the color doesn't appear to make sense. Making this a subroutine and returning an error in the case of an unknown color might make sense. I don't know what this "abbreviate it if you can" idea accomplishes.
Update:
In Section
Seekers of Perl Wisdom
|
|