Solved

Getting rid of \r ?

Posted on 2008-06-12
5
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 9

Expert Comment

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

Accepted Solution

by:
Rob Siklos earned 500 total points
ID: 21770394
try this before you print $token:

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

Author Comment

by:DJ_AM_Juicebox
ID: 21771177
@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
ID: 21771212
nevermind, i need to get some sleep.

Thanks
0
 
LVL 39

Expert Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Six Sigma Control Plans

705 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