[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

Getting rid of \r ?

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
DJ_AM_Juicebox
Asked:
DJ_AM_Juicebox
1 Solution
 
Suhas .QA ManagerCommented:
to end the columns
try print("\r\n");
0
 
Rob SiklosCommented:
try this before you print $token:

$token =~ s/\s+$//;
0
 
DJ_AM_JuiceboxAuthor Commented:
@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
 
DJ_AM_JuiceboxAuthor Commented:
nevermind, i need to get some sleep.

Thanks
0
 
Adam314Commented:
The most common method is to chomp the line when you read the file.  
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now