Printer Friendly Version Print this thread
Email this thread to a friend eMail this thread to a friend
Featured Web Site Template

Hundreds More at Free Site Templates.com!

Web Site Partners
Sponsored Links
Jet City Software
 
Whos Here ?
Reflects user activity within the last 5 minutes
Moderator(s): Prowler, jcokos
Member Message

Curt
Joined: Eons Ago
# Posts: 3747

View the profile for Curt Send Curt a private message

Posted: 2005-Jul-28 01:18
Edit Message Delete Message Reply to this message

No matter how I program this:


Code: [copy]




this particular line: $data2[$a] =~ s/\n//;
will not remove the carraige return at the end. I've tried rewriting that line with these variations:

$data2[$a] =~ s/\n//;
$data2[$a] =~ s/[\n\r]//;
$data2[$a] =~ s/[\n\r]+//;

...and a couple other ways, but always the same result happens. I still get a variable value with some sort of carriage return added to the value. How do I remove the carraige return/new line from the value?

BTW "n" and "r" in the program commands should be "back slash + n" and "back slash + r".

[ Message was edited by: JimBot 07/28/2005 06:47 am ... Reason: Fixed Title and Code. ]





Curt
Joined: Eons Ago
# Posts: 3747

View the profile for Curt Send Curt a private message

Posted: 2005-Jul-28 01:22
Edit Message Delete Message Reply to this message

What happened to my thread title?

Was suppose to be "Can't remove carriage returns w/PERL"

Also, it's a pain when yah can't post code properly with back slashes, etc.



perlworx
Joined: Jul 27, 2005
# Posts: 2

View the profile for perlworx Send perlworx a private message

Posted: 2005-Jul-28 02:48
Edit Message Delete Message Reply to this message

...just use the chomp function


Code: [copy]





[ Message was edited by: perlworx 07/27/2005 08:13 pm ]





Curt
Joined: Eons Ago
# Posts: 3747

View the profile for Curt Send Curt a private message

Posted: 2005-Jul-28 11:35
Edit Message Delete Message Reply to this message

That doesn't make the variable $data2[$a] contain a value without a carraige return. It didn't seem to do anything. Perhaps it was not used in the right place. What does that command do anyway?



perlworx
Joined: Jul 27, 2005
# Posts: 2

View the profile for perlworx Send perlworx a private message

Posted: 2005-Jul-28 21:26
Edit Message Delete Message Reply to this message



Code: [copy]







Curt
Joined: Eons Ago
# Posts: 3747

View the profile for Curt Send Curt a private message

Posted: 2005-Jul-29 03:16
Edit Message Delete Message Reply to this message

Thanks perlworx.

While I ended up using another method, your method helped me find a very similar method:

chop(@data2);

Running it through that command 2 times removed all the new line characters. It seems that when I upload my flat file text database from my computer to my linux server, it interprets the single carraige return as a double carraige return. Weird. Anyways "chop" does the trick. Thanks for leading me to a successful method.



Prowler
Staff
Joined: Aug 14, 2000
# Posts: 1832

View the profile for Prowler Send Prowler a private message

Posted: 2005-Jul-29 06:19
Edit Message Delete Message Reply to this message

Good that you sorted the problem Curt. Sorry I am a little late in answering this topic.

'Chop' would strip the last character no matter what while chomp() will strip the newline alone. When you deal with binary files make sure that you set $/ explicitly to the appropriate value for your file format before using chomp().
You will find more information on Perl usage across different OS here: [link]




masidani
Joined: Oct 21, 2005
# Posts: 10

View the profile for masidani Send masidani a private message

Posted: 2005-Oct-21 15:40
Edit Message Delete Message Reply to this message

chomp is the correct function to use - it removes ALL trailing newlines. chop removes only the last character, regardless of what it is.

E.g.,

#!/ust/local/bin/perl

$str = "aaannn";
chomp $str;
# now contains only "aaa"
chop $str
# now contains "aa"


Simon


You are not permitted to post messages in this forum or topic, because of one or more of the following reasons:
  1. You have not yet logged in, or registered properly as a member
  2. You are a member, but no longer have posting rights.
  3. This is a private forum, for which you do not have permissions.

If you are a recent member, it's possible that you simply have not yet confirmed your account. Please check your email for a message entitled 'JimWorld Forums: Confirm Your Account' and follow the instructions contained within.

If you cannot find this message, click here to Re-Send it.

If you are still experiencing problem, please read the Login Assistance Article for some advice on what may be causing your login not to work properly.

Switch to Advanced Editor and ... Create a New Topic or Reply to this Thread

New posts Forum is locked
© 1995  ·  iWeb, Inc  ·  DBA JimWorld Productions