Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>#!/usr/bin/perl $source_file = "tmp.txt"; $dest_xml_file = "my.xml"; #Check existance of root directory open(SOURCE_FILE, "$source_file") || die "Fail to open file $source_file"; open(DEST_XML_FILE, "&gt;$dest_xml_file") || die "Coult not open output file $dest_xml_file"; $x = 0; print DEST_CS_FILE "&lt;!-- from tmp.txt--&gt;\n"; while (&lt;SOURCE_FILE&gt;) { &amp;ConstantParseAndPrint; } sub ConstantParseAndPrint { if ($x == 0) { # if(/^\s*(constant)\s*(fixup|\/\*fixup\*\/|)\s*(private|)\s*(\w+)\s+=\s+&lt;([a-zA-Z0-9]+)\s+([a-zA-Z0-9])+&gt;\s*(\/\*\s*(.*?)\s*\*\/|)(\r|\n|\s)/) if(/^\s*(constant)\s*(fixup|\/\*fixup\*\/|)\s*(private|)\s*(\w+)\s+=\s+&lt;([a-zA-Z0-9]+)\s+(["']?)([a-zA-Z0-9.:\\]+)\6&gt;\s*(\/\*\s*(.*?)\s*\*\/|)(\r|\n|\s)/) { $name1 = $1; $name2 = $2; $name3 = $3; $name4 = $4; $name5 = $5; $name6 = $7; $name7 = $8; printf DEST_XML_FILE "\t\t$name1"; printf DEST_XML_FILE "\t\t$name2"; printf DEST_XML_FILE "\t\t$name3"; printf DEST_XML_FILE "\t\t$name4"; printf DEST_XML_FILE "\t\t$name5"; printf DEST_XML_FILE "\t\t$name6"; printf DEST_XML_FILE "\t\t$name7\n"; # $x = 1; } } } </code></pre> <hr> <hr> <hr> <p>Use the following parse code:</p> <pre><code>if(/^\s*(constant)\s*(fixup|\/\*fixup\*\/|)\s*(private|)\s*(\w+)\s+=\s+&lt;([a-zA-Z0-9]+)\s+(["']?)([a-zA-Z0-9.:\\]+)\6&gt;\s*(\/\*\s*(.*?)\s*\*\/|)(\r|\n|\s)/) </code></pre> <p>I have added handling of both the single and double quotes. I use back-reference for quotes matching. Also I have updated the character class for path. i.e. it now includes the colon(:), dot(.), and backslash() along with alpha-numeric characters.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload