"^" is considered to be an assertion, it gives you more control, so here the "^" makes you match the beginning of the line, without it there, the program logic would go back and do another loop journey every time it encounters "\n" but you want to only capture those new-line characters that happen at the beginning , you got other assertions to match the end of the line or string or word boundary...etc, read about them,because regular expression is so important in Perl,without it you are in a fix
"\" in \n is an escape character, it helps to extend a meaning to an otherwise normal letter, like t and \t are not the same thing
the most important feature here in your question is the "and", this is sort of an if statement but in a different way, Marshall has given you useful tips on other ways to achieve the same thing, here I would just add to you that this special "and" is called "logical and" operator, it works as a short-circuit, that is, unless the left expression is true it would not proceed to evaluate the right expression or operand since operators work on operands mostly right?
so what happened here is that if the left expression is true, (a string beginning with a new line) the "and" would evaluate the right expression, next, next means repeat over the loop from the start again.In reply to Re: About a piece of code
by biohisham
in thread About a piece of code
by trewq
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |