Perl script lines to remove lines
|
Original Message
|
Name: John
Date: July 14, 2003 at 08:54:54 Pacific
Subject: Perl script lines to remove linesOS: XPCPU/Ram: 256 |
Comment: We have these files that are backed up on the serber into files. Sometimes it comments the first couples lines in the file causing an error. We need to completely remove the // and /*'s from the file. I put into the pl file $filename =~ s/^.*//.*$//g; $filename =~ s/^.*/*.*$//g; Is this right am I going about this all wrong? Please email me!! I need help ASAP!!
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: SN
Date: July 14, 2003 at 11:52:39 Pacific
Subject: Perl script lines to remove lines |
Reply: (edit)I've e-mailed you the following (duplicated here in case I did it wrong and somebody can correct me or suggest a better way) You want to remove the entire line/comment. Let me change what I wrote to include a "any character any number of times" part, .* Also, since you are doing this in the file, the ^ and $ will only match at the beginning and end of the file, rather than beginning and endings of lines. So you need the /m modifier as well as the /g. $filename =~ s/^\/\/.*?$//gm; - removes any ocurrences of // at the beginning of the line $filename =~ s/^\/\*.*?\*\/$//gm; - removes anything between /* and */ the question marks tell it to match as few characters as possible. -SN
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: FishMonger
Date: July 15, 2003 at 17:34:55 Pacific
Subject: Perl script lines to remove lines |
Reply: (edit)If you use a different delimiter for the regex, you won't need to escape the / and it would be easier to read and understand what the regex is doing. So, the regex's would look like this: s|^//.?$||gm s|^/\*.*?\*/$||gm
Report Offensive Follow Up For Removal
|
Use following form to reply to current message: