in reply to exiting loops
Your two calls to last are meaningless since they appear at the end of their individual blocks; there's nothing else that would have been executed anyway. What I mean is that last is exiting the if conditional block, not the outter loop. There isn't any code to be executed after the if conditionals, aside from the next. Similarly your next NEWLINE is also meaningless since it is the last line of the while block. ...and the while block is named NEWLINE. Meaningless, because you're at the end of the block anyway, there's nothing more for Perl to do besides loop again, even without the 'next' call. You might derive some benefit from looking at perlsyn, where control flow is discussed.
If I wanted to print a newline before every line that begins with '10', I would do it this way:
perl -pi.bak -e "m/^10/ and $_ = $/ . $_;" filename.txt
That you can disect after reading perlrun (to gain an understanding of one-liners), perlop (to look into logical short circuit operators), and perlvar (to see that $/ defaults to the newline character). Hope this is helpful.
Dave
|
|---|