tshabet has asked for the wisdom of the Perl Monks concerning the following question:
into XML like this{bob is {a cool guy}}
Here's the code I've written (edited for stuff that I know is fine/user outputs/etc)<bob> is <a> cool guy </a></bob>
#!/usr/bin/perl -w use diagnostics; use Parse::RecDescent; use Text::Balanced qw( extract_bracketed ); #input print "Name of file to be inputted? :"; $infile=<>; print "What should the output file be named? The file will be automati +cally created. :"; $outfile=<>; chomp $infile; $/=undef; open INFILE, "<$infile"; $text=<INFILE>; close INFILE; #processing my $counter = 0; while($next = (extract_bracketed($text, '{}', '[^{}]*' ))[0]) { $holder = $next; while($bext = (extract_bracketed($next, '{}', '(?s).*?(?=\{code)' +))[0]) { $bolder = $bext; while($cext = (extract_bracketed($bext, '{}', '(?s).*?(?=\{escape) +' ))[0]) { $colder = $cext; $cext =~ s/\{([^ \s|\}]*?)\}/<$1\/>/gix; $cext =~ s/\{([\w|-]*)(.*)\}/<$1>$2<\/$1>/osi; $bext =~ s/$colder/$cext/sgi; } $bext =~ s/\{(\w*?)\s(.*)\}/\<$1\>$2<\/$1>/gosix; $bext =~ s/\{metavar(.*?)\}/<metavar>$1<\/metavar>/gosix; $bext =~ s/\}/ebrac/g; $bext =~ s/\{/obrac/g; $next =~ s/$bolder/$bext/sgi; } $next =~ s/\{([^ \s|\}]*?)\}/<$1\/>/gix; $next =~ s/\{([\w|-]*)(.*)\}/<$1>$2<\/$1>/osi; $text =~ s/$holder/$next/sgi; print "Sync check \#$counter\n"; print "$next\n"; $counter++; } #output open FILEOUT, ">$outfile"; print FILEOUT $text; close FILEOUT; print "\nYour result is stored in file $outfile\nGoodbye.\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 1: Code stalls...possible memory leak?
by tilly (Archbishop) on Aug 21, 2001 at 21:38 UTC | |
|
Re: Code stalls...possible memory leak?
by John M. Dlugosz (Monsignor) on Aug 21, 2001 at 20:52 UTC | |
by tshabet (Beadle) on Aug 21, 2001 at 21:39 UTC | |
by John M. Dlugosz (Monsignor) on Aug 22, 2001 at 00:18 UTC | |
|
Re: Code stalls...possible memory leak?
by filmo (Scribe) on Aug 21, 2001 at 21:18 UTC | |
|
Re: Code stalls...possible memory leak?
by Cine (Friar) on Aug 21, 2001 at 22:22 UTC | |
|
Re: Code stalls...possible memory leak?
by jryan (Vicar) on Aug 21, 2001 at 21:11 UTC | |
by chromatic (Archbishop) on Aug 22, 2001 at 06:39 UTC | |
|
Re: Code stalls...possible memory leak?
by tshabet (Beadle) on Aug 21, 2001 at 21:58 UTC |