Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > Perl

Perl Discussion for the PERL language - Practical Extraction and Reporting Language, is a programming language often used for creating CGI programs.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-13-2007, 06:19 PM
policy policy is offline
Newbie
 
Join Date: Jul 2006
Posts: 4
Rep Power: 0
policy is on a distinguished road
Default Remove newline

I'm printing the lines from a text file.

As I read the lines I would like to remove the linebreak but I can't seem to get it working.

I have tried this:

Perl Code:
  1. $line =~ tr/\015//;
  2. $line =~ tr/\n//;
  3. $line =~ tr/\r//
  4.  

But it doesn't seem to work. Any ideas?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-14-2007, 02:14 PM
KevinADC KevinADC is offline
Learning Programmer
 
Join Date: Jan 2007
Posts: 91
Rep Power: 7
KevinADC is on a distinguished road
Default

tr/// has no concept of what you are trying to do, s/// would work (I think) but perl has the chomp() function which is specifically for removing the input record seperator (or line endings) which is by default a newline (\r\n on windows).

Code:
chomp($line);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-15-2007, 09:49 PM
policy policy is offline
Newbie
 
Join Date: Jul 2006
Posts: 4
Rep Power: 0
policy is on a distinguished road
Default

I was not aware of the chomp() function. This works fine for my purposes. thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-19-2007, 07:56 AM
Bram Bram is offline
Newbie
 
Join Date: Sep 2007
Posts: 2
Rep Power: 0
Bram is on a distinguished road
Default

You could also use something like :

open(F,"<$ARGV[0]") or die("No file specified.\n");
my @data=<F>;
close(F);

my $blah=join("",@data);

# notice m
$blah =~ s/[\n\r]//mg;

print $blah;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to remove your second XP without formating - [With Video] Onur Tutorials 1 08-31-2007 08:42 AM
Remove Autofill in FF falco85 JavaScript and CSS 1 07-04-2007 11:19 AM
Remove Leading 0's NeedHelp Perl 7 04-16-2007 02:09 PM
Tutorial to Remove the Virus "Trojan horse Startpage.ADE" clookid Tutorials 9 01-09-2007 10:39 PM


All times are GMT -5. The time now is 04:44 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads