Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Ok here is a very rough and ugly start to how I think your suggesting I should go about compiling aXML files. I know this code is _AWFUL_, but it does work and it's quite fast at turning an aXML file into a bunch of print statements and axml function calls which could be very quickly parsed by my existing parser system as they are very short. I guess I would want to save the output of this program on first run so I can skip this step on subsequent runs. This only supports <> type tags.

use Modern::Perl; use Time::HiRes qw( gettimeofday tv_interval ); my $start = [ gettimeofday ]; my $aXML_ENV = { qd => { a => 'b', b => 'c', c => '42' }, conf => { x => 'y', foo => '1', bar => '2' } }; my $plugins = { qd => '$result = $aXML_ENV->{"qd"}->{$data}', conf => '$result = $aXML_ENV->{"conf"}->{$data}' }; my $aXML_string = qq@ some other data that needs to be output as well <qd><qd><qd>a</qd></qd></qd> = 42 <conf>bar</conf> <sometag>thatdoesnothing</sometag> but also needs to be present in the output <conf>foo</conf> <someothertag>thatalsodoesnothing</someothertag> as far as aXML is concerned, but obviously used by whatever program we are sending this data too. @; sub sortofcompileit { my $aXML_ENV = $_[0]; my $plugins = $_[1]; my $aXML_string = $_[2]; my $compiled_string_start; my $compiled_string_end; my $compiled_string_middle; my @commands; my $command_opens_string = "("; my $command_closes_string = "("; my $mong_string; while ( my ($key, $value) = each(%$plugins) ) { push (@commands, $k +ey); } map { $command_opens_string .= "<$_>|" } @commands; map { $command_closes_string .= "</$_>|" } @commands; chop $command_opens_string; chop $command_closes_string; $command_opens_string .= ")"; $command_closes_string .= ")"; #find the position of the first command #set everything before it to be printed if ($aXML_string =~ m@^(.*?)$command_opens_string@s) { $compiled_string_start = 'print qq@'; $compiled_string_start .= $1; $compiled_string_start .= "@;\n\n"; } $mong_string = 'use aXML;'; $mong_string .= "\n"; $mong_string .= $compiled_string_start; #find everything in the middle if ($aXML_string =~ m@$command_opens_string(.*)$command_closes_stri +ng@s) { $compiled_string_middle = "<axml>$1$2$3</axml>"; } #find anything in the middle which is inbetween any type of close #and open and set it to be printed out my $replacement; $compiled_string_middle =~ s@$command_closes_string@`$1@gs; while ($compiled_string_middle =~ m@(.*?)$command_closes_string([^` +]*?)$command_opens_string@gs) { $replacement = "$1$2</axml>\n\n"; $replacement .= 'print qq@'; $replacement .= $3; $replacement .= "@;\n\n<axml>$4"; $mong_string .= $replacement; } $compiled_string_middle =~ s@`@@gs; if ($compiled_string_middle =~ m@.*$command_opens_string(.*?)$comma +nd_closes_string</axml>$@s) { $mong_string .= "$2$3</axml>\n\n"; } #find the position of the last close tag #set everything after it to be printed if ($aXML_string =~ m@.*$command_closes_string(.*)$@s) { $compiled_string_end = 'print qq@'; $compiled_string_end .= $2; $compiled_string_end .= '@;'; } $mong_string .= $compiled_string_end; $mong_string =~ s@`@@gs; $mong_string =~ s/<axml>(.*?)<\/axml>/print axml\(qq\@$1\@\);/g; return $mong_string; } my $sortofcompiled_string = sortofcompileit($aXML_ENV,$plugins,$aXML_s +tring); say $sortofcompiled_string; my $end = [ gettimeofday ]; my $total_elapsed = tv_interval($start,$end); say "elapsed = $total_elapsed";

In reply to rough start of an axml compiler by Logicus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-20 02:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found