it wil take a more experienced person than me to explain why this is, but if your line only contains the \n at the very end, and it should, you do not use the end of string pattern anchor ($) if that is what you are doing. Since there is only one \n what you need to do is search for /\w\n/ only. Since you did not post the code you are attempting to use I can only offer a generic example:

Thanks for the reply KevinR. Let me clarify a little. Take this sample file for example:

abc def ghi

A search in VI for :/\w\n will find the last letter (c, f, and i) in each line and the \n at the end of each line.

But in Perl, a match for \n works, but I get no matches with a search for \w\n only a match when using \s\n.

sample code to count matches:

my $count=0; while ($stext =~ /\w\n/g) { $count++; }

So why does VI match \w\n with no problem but Perl does not in the same file? The \w\n pattern is not hard to identify. What do people use to clearly see all visible and special characters in a file?

I don't know what VI is so I can't answer that. Your "while" loop might just run forever if the match returns true. Thats not good! It would be better as an "if" condition:

$count=0; if ($stext =~ m/\w\n/) { $count++; }

how to view hidden characters in files? Good question, I have an editor that shows hidden characters, it shows a paragraph symbol for the \n character but I don't know how to post character entities on this message board. (Its a funny looking P). Shows -> for tabs and etc. -------------------------------------------------

Thanks for the suggestions KevinR. All of those are ways to setup the code to find and count matches, but Perl is not finding the regular expression I specify. My basic question is why does Perl not find \w\n when it seems to clearly be present in the text file - vi matches the string \w\n and Perl finds the correct number of \n, just not \w\n (it sees \s\n instead).

My last post is not a "setup", it opens a text file, any text file, and looks for the combination of \w\n and if it is present it will increment the count, I thought that is what you wanted to do. Your way will not work. It might with VI, but not with Perl.

There is no trick in my code, it will rteturn true if \w\n is matched and false if its not matched. If you must put your file into an array that will also work:

open(FILE,"yourfile.txt");

@array = <FILE>;

close (FILE);

$count = 0;

for (@array) {

$count++ if (/\w\n/);

}

but my other code will be a little easier on the sytem resources if its a big file since its not loading the file into memory (@array) but reading directly from the file. But if you insist on doing your way:

$stext = "@text";

then trying that while loop you posted, it will not work. VI might beable to do it that way, but Perl will not.