|Do you know where your variables are?|
Climbing Mt. Perlcritic -- Switch statementsby chexmix (Hermit)
|on Mar 25, 2009 at 17:44 UTC||Need Help??|
chexmix has asked for the
wisdom of the Perl Monks concerning the following question:
Salutations, Monks -
A few weeks ago I posted a node about an issue with the map function I had encountered while attempting to make a script PerlCritic-compliant.
I have hit another problem. In an effort to satisfy PerlCritic's complaint about undue complexity, I am attempting to turn the following nested if:
... into a switch statement. I am doing this because in another instance, it knocked a couple of points off the complexity score. So I'm hoping for the same result here. Anyway, here is the current version of the replacement:
... note this is inside a foreach loop. Anyhoo, here is the error this is throwing:
Thing is, I think I understand what is happening here but not why: essentially, the call to basename() is not finding a good value in $1, which should have been returned from the match by the (\S+). So:
I suspect it will sound overweening of me to say so, but I would prefer this not turn into a thread (IF it turns into a thread ... this could be a stupid question!) about the merits and/or drawbacks of PBP and why I should or should not be trying to satisfy the damned thing's complaints. Its use has been mandated, and I'm trying to use it as a learning tool. It's actually kind of fun - like a puzzle.
Besides, all the PBP anti- and for stuff has been well hashed out here, I think. Just my 2c.