Solved

Getting rid of \r ?

Posted on 2008-06-12
5
174 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 .
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 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

22 Experts available now in Live!

Get 1:1 Help Now