CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [vishwakar] Have to exclude the first and last line of the file : help me: Edit Log



Zhris
Enthusiast

Dec 24, 2010, 11:26 AM


Views: 3955
Re: [vishwakar] Have to exclude the first and last line of the file : help me

The array "@lines" contains all the lines in your input file except the first and the last. You need to then output the array to your output file.

If you want to edit a file in place, you would need to look into a module like Tie::File. This module is also great for handling large data.


Code
open my $inputfh, '<', 'Input.txt' or die "cannot open Input.txt - $!"; 
my @lines = <$inputfh>;
close $inputfh;

shift @lines;
pop @lines;

open my $outputfh, '>', 'Output.txt' or die "cannot open Output.txt - $!";
print $outputfh "@lines";
close $outputfh;

#rename ('Output.txt', 'Input.txt');


Chris


(This post was edited by Zhris on Dec 24, 2010, 11:35 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Dec 24, 2010, 11:32 AM
Post edited by Zhris (Enthusiast) on Dec 24, 2010, 11:33 AM
Post edited by Zhris (Enthusiast) on Dec 24, 2010, 11:34 AM
Post edited by Zhris (Enthusiast) on Dec 24, 2010, 11:35 AM
Post edited by Zhris (Enthusiast) on Dec 24, 2010, 11:35 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives