newbie perl editing question

I am trying to edit and upload some perl scripts I found on the net, from my win98 machine to a unix one.  If I edit them in notepad they work fine.  If I use wordpad or word, they don't; I think some newline characters are being tacked in? I have one script that is too large to use with notepad.  I tried to make a script that would strip out the newlines, and the file size did decrease, but it still won't work.  Here's the script I was trying to "chomp" with:

#!/usr/bin/perl
print "Chomp up what file: ";
$filename=<STDIN>;
chomp $filename;
open(FILE,$filename);
$/="\r\n";
while(defined($target=<FILE>)) {
  chomp($target);
  $stuff.=$target;
}
close(FILE);
open(NEW,">new.cgi");
print NEW $stuff;
close(NEW);
print "Chomped $filename";

I'm looking for one of three answers:
a. Tell me how to edit a large file without putting newlines in,
b. tell me how to make some type of script like the one above to strip them out after, or
c. tell me I'm totally offbase, and what the real reason is this darn thing isn't working. 8-)
(I'm a total perl/unix newbie)
Thanks
phantrosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobWMartinCommented:
Instead of chomp($target), try $target=~s/\r//
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobWMartinCommented:
Also, leave out the $/="\r\n".  The chomp is taking out both the \r and the \n.  Or you could leave in the $/="\r\n" and the chomp($target), then change to $stuff.="$target\n" (i.e. add the \n).

0
maneshrCommented:
if i understand you right, you get some strange character in your script when you transfer your file from Win98 to Unix, right??


If yes, you might be seeing ^M chars.

This is due to the fact, as you might already know, that DOS/Win* use 2 chars to denote end of line char where as UNIX used only one.  Therefore the extra char is not because of something you have/have not done.

b. tell me how to make some type of script like the one above to strip them out after, or


there is more than one way of doing this.

I) IF you are using the vi editor, in UNIX to edit that file, you can use the foll ..

Lets say the script name is test.pl. At the prompt type..

1 - vi test.pl and press the enter key
2 - press escape key. press Shift + ; and type the foll

1,$s/^M//g

yes this is very similar to the PERL search and replace pattern.

what you are saying is from line no 1 to end of file search for the ^M char and remove it globally. NOTE: to reproduce the ^M char , keep the CTRL key pressed and press v and them m (so you get a SINGLE char ^M)

II) If you want to use a PERL script, change your script to ......

#!/usr/bin/perl

print "Chomp up what file: ";
$filename=<STDIN>;
chomp $filename;
open(FILE,$filename);


##$/="\r\n";

$/="^M";
## To reproduce the control char, keep the ctrl key pressed and press v followed by m.

while(defined($target=<FILE>)) {
chomp($target);
$stuff.=$target;
}
close(FILE);
open(NEW,">new.cgi");
print NEW $stuff;
close(NEW);
print "Chomped $filename";
=================================================
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Kim RyanIT ConsultantCommented:
You could try some shareware programmers editors like TextPad or EditPlus. They allow you to choose either Unix or Windows style line terminators, and will edit large files. This should be easier than having to run conversion scripts over your programs all the time.
0
monasCommented:
phantros,

      if the only problem uploaded scripts have \r's at the end of line - upload your scripts via ftp in TEXT (!!!!! :-) mode!
0
RobWMartinCommented:
Hold on there, monas.  You are making things look too easy :^)

0
monasCommented:
There were cases when this had help :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.