Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extremely Basic Question: /^$/ and \n 1

Status
Not open for further replies.

Meiguoren

Technical User
Jun 16, 2008
4
Hello all,

I know that /^$/ is used to match an "empty" line. But most "empty" lines contain a carriage return, right?

What follows are two "empty" lines:


If I use the following script on an input file containing nothing but two such blank lines, the substitution is successful:

Code:
open (INPUT, "input.txt"); 

while(<INPUT>){

s/^$/bass/;
print;

}

close INPUT;

But I know that the diamond operator <> reads up to and including a newline character (or whatever $/ is defined as at the time). So shouldn't the match see a '\n' and bail?

Thanks for your help.
 
the short answer is that the "$" anchor matches before a \n at the end of a line or string.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top