in reply to What's happening to my $1?
Others have fleshed out the whys and wherefors wrt the behavior you've experienced, but I just wanted to mention that perhaps some important information has left the perl documentation. For as long as I can remember (since 1992ish) I've always followed the practice that the numbered vars are only good until the next match that contains parenthesised bits (regardless of that match's success or failure). I think I read in the perl man page at the time or perhaps in the pink camel that this was the only safe way to proceed and it's never steered me wrong. Perhaps that has gone missing from the docs (I didn't see it just now when I looked) or maybe perl is actually supposed to not clobber $1 and friends unless the entire pattern matches. Either way, I think a doc patch is necessary.
|
|---|