hsmyers has asked for the wisdom of the Perl Monks concerning the following question:
With the idea of stripping off the optional first two characters and returning the last character. For instance dis('QNP') returns 'P' and so on. To my surprise, this worked---at least seemed to at first. It turns out that in some cases this works, but in others, there are strange side-effects that that leave you looking at once working code that perl now claims is defective. Lucky for me, I typically change only one thing at a time before regression testing and it was fairly easy to spot this one. Here is the patched code:sub dis { shift =~ /.?.?(.)/; }
The reason I labeled this node a puzzle is that I've no clue as to what was wrong or why this fixes it! So I ask the more knowledgeable out there, what is going on here?sub dis { shift =~ /.?.?(.)/; $1; }
--hsm
"Never try to teach a pig to sing...it wastes your time and it annoys the pig."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Parse Puzzle
by merlyn (Sage) on Mar 30, 2003 at 06:26 UTC | |
|
Re: Parse Puzzle
by diotalevi (Canon) on Mar 30, 2003 at 06:27 UTC | |
|
Re: Parse Puzzle
by runrig (Abbot) on Mar 30, 2003 at 06:26 UTC | |
by merlyn (Sage) on Mar 30, 2003 at 06:30 UTC |