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

Help needed with removing carriage returns

Status
Not open for further replies.

dkape

MIS
Mar 22, 2001
17
0
0
US
I have a script which parses through a test document ans removes unwanted lines. What I am having trouble doing is stripping away carriage returns for lines that meet a predetermined criteria. The following is a portion of the script.
while(<STDIN>) {
/^ Some text matching:(.*)/ && do {
# Strip off the first part of the message text lines
$_ = $1;
last DATA_IN;
};
/^ THIS TEXT:(.*)/ && do
{
# Strip off the first part of the message text lines
$_ = $1;
last DATA_IN;
};
}
I would like to have only the lines that start with 'THIS TEXT:' strip the 'THIS TEXT:' portion, which is working right now, AND also remove any carriage returns from the matched lines. I've been trying the chop and chomp functions but always seem to remove lines from output that I am not intending to. Any help would be appreciated
Thanks,
Doug
 
chomp should work for you. Sometimes it helps to use the name of the variable when you chomp like this;

chomp($thisvar);

Have you tried it this way?

BTW; if you use chop it will chop off the last character from the end of the line.
If it's a '\n' (newline) then that's what it will chop but if there's no '\n' then it will chop whatever it finds there.

Hope this helps! tgus

____________________________
Families can be together forever...
 
I think most perl programmers would advocate always using chomp, since you'll usually see the comment &quot;get rid os pesky newlines&quot; after the chomp() function.
Since you are dealing with $_ you can just put a chomp after;

while(<STDIN>) {
chomp;
#more code
}

if you desperately need the newline to print you can always add it later.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top