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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple regexp to filter out #'s and *'s

Status
Not open for further replies.

gcazian

MIS
Dec 4, 2002
61
US
Hi all, I have a file that I want to open as a file handle and only retrieve lines that don't have a hash mark, an asterisk, or a line that looks like this:

# ****************************

I have tried /[^#*]/ but it doesn't work. Anyone have any tips?
 
Show the code you have been trying, it may just need a minor change to work. In general:

Code:
open(FH,'file.txt') or die "$!";
while(<FH>) {
   !/[#*]/ && print;
}
close(FH);

by hash mark I assume you mean the pound sign: #
 
If your convention is that comment lines always start with a # character in the first poition on the line, then the fact that you have a whole load of ***** after it is just complicating it.

To ignore any line that begins with a # you can put this line at the beginning of the inside of the loop that reads the file:

Code:
   next if /^#/;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top