Perl

Moderators: Jonathan
Number of threads: 1259
Number of posts: 3644

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Deleting line spacing Posted by Esmebabe on 15 Feb 2004 at 11:58 PM
Is there a code to delete the line spaces between sentences or words in a file?
I mean when i've word like this:

-> Input.txt



1.The file you are looking for might have been moved.


2.If you typed the address in the navigation bar.

i.e. maybe with 2-3 line spacing,and i need to remove the line spaces to:

-> Output.txt

1.The file you are looking for might have been moved.
2.If you typed the address in the navigation bar.


Report
Re: Deleting line spacing Posted by Jonathan on 16 Feb 2004 at 3:35 AM
: Is there a code to delete the line spaces between sentences or words
: in a file?
Yup.

: I mean when i've word like this:
:
: -> Input.txt
:
:
:
: 1.The file you are looking for might have been moved.
:
:
: 2.If you typed the address in the navigation bar.
:
: i.e. maybe with 2-3 line spacing,and i need to remove the line spaces to:
:
: -> Output.txt
:
: 1.The file you are looking for might have been moved.
: 2.If you typed the address in the navigation bar.
:
Two methods:-

1) If the file is reasonably small, read the file into an array, so there is one line per element, then grep for non-empty lines.

@lines = grep { $_ ne "\n" } @lines;

2) If it's a bigger file, loop through it.

open IFILE, "< input.txt";
open OFILE, "> output.txt";
while (<IFILE>) {
    print OFILE $_ unless $_ eq "\n";
}
close IFILE;
close OFILE;


Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.