
alalleyn
Novice
Apr 28, 2002, 3:17 AM
Post #1 of 2
(1176 views)
|
|
Writing certin sections of file to new file
|
Can't Post
|
|
A brief explanation of what I am trying to do is copy all the information between programlisting and /programlisting to a new outputfile. I have the following script that I think should do this for me but it seems not to work and I was wondering if somebody could tell me where I am going wrong with it and hopefully point me in the right direction. I have also enclosed a copy of my test input file incase this comes in handy. use strict; use diagnostics; use CGI(); use CGI::Carp qw(fatalsToBrowser); use Fcntl qw(:flock); my $query = new CGI; my $file = $query -> param('file'); open (TXT, $file) or die "Can't open $file: $!"; flock(TXT, LOCK_SH); # no one can edit the file now. my @text = <TXT>; push @alllines, $_ while(<TXT>); my $codestarts = 0; my $codeends = 0; my @currentlist; my @biglist; foreach $test (@allines) { if ($test =~ /<\/progamlisting>/) { $codesends = 1; } elsif ($codeends == 1) { foreach $test (@currentlist){ $currentlist = ($currentlist. $test); } push @biglist, $currentlist; $currentlist =(); @currentlist = @_; $codeends = 0; } if ($test =~ /<progamlisting.*>/) { $codestarts = 1; } elsif ($codestarts == 1) { push @currentlist, $test; } close (TXT); open(OUT, ">Welcome.java"); foreach $line (@currentlist){ print "$line \n"; } close(OUT);
|