Closed Thread
Results 1 to 4 of 4

Thread: Remove newline

  1. #1
    policy is offline Newbie
    Join Date
    Jul 2006
    Posts
    4
    Rep Power
    0

    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:

    [HIGHLIGHT="Perl"]
    $line =~ tr/\015//;
    $line =~ tr/\n//;
    $line =~ tr/\r//[/HIGHLIGHT]

    But it doesn't seem to work. Any ideas?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    KevinADC is offline Programmer
    Join Date
    Jan 2007
    Posts
    125
    Rep Power
    0
    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);

  4. #3
    policy is offline Newbie
    Join Date
    Jul 2006
    Posts
    4
    Rep Power
    0
    I was not aware of the chomp() function. This works fine for my purposes. thanks!

  5. #4
    Bram is offline Newbie
    Join Date
    Sep 2007
    Posts
    2
    Rep Power
    0
    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;

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. MASM [help] remove dll from exe
    By Zero_Cool in forum Assembly
    Replies: 11
    Last Post: 09-09-2011, 11:06 AM
  2. Want to remove Ads from website
    By graphic360 in forum PHP Development
    Replies: 1
    Last Post: 01-01-2011, 02:19 AM
  3. How Do I remove?
    By byronwells in forum Database & Database Programming
    Replies: 2
    Last Post: 03-11-2010, 07:38 PM
  4. remove
    By zhenya in forum C and C++
    Replies: 1
    Last Post: 12-31-2009, 02:09 PM
  5. Remove ln -s
    By Jame in forum Linux/Unix General
    Replies: 4
    Last Post: 10-23-2007, 09:41 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts