Solved

Getting rid of \r ?

Posted on 2008-06-12
5
173 Views
Last Modified: 2010-03-05
Hi,

I made a csv file on a windows machine, its contents are just like:

  5 10 15
  2 4 6
  3 6 9

I tokenize the input, then just print the matrix as a test. I print brackets around the numbers. It works fine on a windows machine. It looks like:

   Row 0: [5] [10] [15]
   Row 1: [2] [4] [6]
   Row 2: [3] [6] [9]

When I move to a solaris machine running perl 5.8.8, for some reason, the closing bracket that was supposed to be at the end of the line eats what was supposed to be the first character in the line! The last printed line looks ok:

   ]ow 0: [5] [10] [15
   ]ow 1: [2] [4] [6
   Row 2: [3] [6] [9]

My print statements are just like:

    print("Row", $r, ": ");
    # for all columns
       print("[");
       print($token);
       print("]");
    #end all columns
    print("\n");

It's definitely something with the value of $token. If I remove that print statement, everything gets printed  fine. I'm thinking that since I made the csv file on a windows machine, it's got some windows character for a new line that is making the output get messed up on the solaris machine?

Is there a way to completely trim any junk off the end of the token to see if that's a problem?

Thanks

   
0
Comment
Question by:DJ_AM_Juicebox
5 Comments
 
LVL 9

Expert Comment

by:Suhas .
Comment Utility
to end the columns
try print("\r\n");
0
 
LVL 9

Accepted Solution

by:
Rob Siklos earned 500 total points
Comment Utility
try this before you print $token:

$token =~ s/\s+$//;
0
 

Author Comment

by:DJ_AM_Juicebox
Comment Utility
@rob263

Yeah that works pefectly. But is there anyway to assign the token as the result of the regex operation? Something like:


$token = "155\r\n";

$token = $token =~ s/\s+$//;

# token is now just "155".


Thanks
0
 

Author Comment

by:DJ_AM_Juicebox
Comment Utility
nevermind, i need to get some sleep.

Thanks
0
 
LVL 39

Expert Comment

by:Adam314
Comment Utility
The most common method is to chomp the line when you read the file.  
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now