LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-12-2006, 12:01 PM   #1
thelonius
Member
 
Registered: Aug 2005
Location: Montréal
Distribution: Debian Testing, Slackware 10.2
Posts: 136

Rep: Reputation: 15
perl's chomp under Win-Linux


Hello,

I have adata file produced under Windows and I treat it with Perl under Linux. The problem I have is that 'chomp' doesn't work in this configuration.

Any idea what to do ?

Thanks.
 
Old 04-12-2006, 01:25 PM   #2
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
You need to remove the Windows carriage return from the lines as well. You see, when a text file is created under Windows, it ends the lines with a carriage return and a line feed, whereas *nix systems use just a line feed. You can use Perl, tr, sed, or a host of other programs to remove this extra character. Here is a simple Perl script to remove these extra characters and format the text file properly.
 
Old 04-12-2006, 01:29 PM   #3
thelonius
Member
 
Registered: Aug 2005
Location: Montréal
Distribution: Debian Testing, Slackware 10.2
Posts: 136

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by scuzzman
You can use Perl, tr, sed, or a host of other programs to remove this extra character.
...other program like 'dos2unix', but I don't want it. I'd like that Perl takes care about it. But it seams that this is not the case.

Thanks.
 
Old 04-12-2006, 03:13 PM   #4
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
Then you didn't read my entire post. Try that one again. (Hint: check out the script I linked to)
The specific section I'm referring to is here (better read in-context):
Code:
   while (<OLD>) {
      if ($opt_replace) {
         s/\r/\n/g;          # replace all (/g) \r's by \n's
      } else {
         s/\r//g;          # replace all (/g) \r's by nothing
      }
      print NEW       or die "can't write $new: $!";
   }
This is just a hint of the power of Perl's regular expression implementation. Take a look here.

Last edited by scuzzman; 04-12-2006 at 03:25 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
link dies intermittently-seemingly at random- between win<->linux not linux<->linux?? takahaya Linux - Networking 10 03-09-2007 11:37 PM
perl's system() command paul_mat Linux - Software 3 11-21-2005 02:37 AM
My instructions are for Linux, but I work in Win...what is the win equialent of (~)? michaelton Linux - Newbie 2 05-21-2004 12:15 PM
Windows<-->Linux box. Linux sees win, not vice versa NPSHr Linux - Networking 7 10-16-2003 10:41 PM
Install linux (mandrake 9.1) over win 98 and still boot linux and winxp(drive E:) BlueTaurus13 Linux - General 12 09-01-2003 09:03 AM


All times are GMT -5. The time now is 04:09 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration