Thank you all for the words of wisdom.
As
tadman points out,
it makes sense that variables $1 etc keep their values in inner scopes - I might need them! However, if local($1,$2,$3)
did exactly what local($x,$y,$z) does, namely save the outer scope values and undefine the localized ones,
the behavior would be simpler to understand and to control. <a href="http://www.perlmonks.org/index.pl?node_id=61482&lastnode_id=61478>
japhy would pperhaps agree.
<a href="http://www.perlmonks.org/index.pl?node_id=61482&lastnode_id=61478>
japhy would probably agree.
Lessons learned:
- Don't rely on the values of $1 etc except in very simple situations (e.g. a single match in the scope)
- Save contents of $1 etc in own named variables, possibly using the list assignment
Your use of a split(), however, is a scary sight to behold,
tadman writes.
OK, it may be inefficient, but it separates the concerns neatly.
Split produces a list in which separator-strings and blocks-between-separators alternate.
I can confidently walk down the list and examine and/or modify each block
without worrying at the same time about where the block ends. Assuming, of course, that the
regex used in split correctly identifies all separator-strings in the text.
Rudif