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: [mhx] Repeatly reading information between two tags: Edit Log



alalleyn
Novice

May 19, 2002, 2:10 PM


Views: 1062
Re: [mhx] Repeatly reading information between two tags

Mhx, Hope you dont mind me getting back in contact, but this might be a little clearer as to excatly what my problem is. I have written the following Perl Code which should write to given output file all the programlisting sections, however it only seems to copy across the first section. Ulimatley I would like all of them copied across and am tearing my hair out to see why it is not.


Code
#!C/usr/bin/perl 

#use strict;
use diagnostics;
use CGI();
use CGI::Carp qw(fatalsToBrowser);
use Fcntl qw(:flock);

my $file = $query -> param('file');
my $output = $query -> param ('output');

open (TXT, $file) or die "Can't open $file: $!";
#flock(TXT, LOCK_SH); # no one can edit the file now.
while (<TXT>) {
@code = ($text) = do { local $/=undef; <TXT> } =~ /<programlisting>(.*?)<\/programlisting>/gsi;
}
close TXT;

open (OUT, ">$output") or die "Cant write to $output: $!";
print OUT @code;
close (OUT);

print "Content-type: text/html\n\n";
print "<html><h1>A source file has been created!</h1>\n";
print "Please feel free to open $output and use at ones pleasure</html>\n";


The input file that I am using is as attached and the generated output is

-- This is smaple code in Java, using Hello World
-- From the first scrap
public class Welcome {


Why does it only do the first section? I think that I am doing correctly. Hopefully I have made myself a little clearer now and am eagley awaiting any useful input.
Thanks again for any help that you can offer.
Andrea


(This post was edited by alalleyn on May 19, 2002, 2:22 PM)


Edit Log:
Post edited by alalleyn (Novice) on May 19, 2002, 2:22 PM


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

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