Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I extract and parse quoted strings in Perl?
    text
    copied!<p>Good day.</p> <p>My text file content below. tmp.txt (a very big size file)</p> <pre><code>constant fixup private AlarmFileName = &lt;A "C:\\TMP\\ALARM.LOG"&gt; /* A Format */ constant fixup ConfigAlarms = &lt;U1 0&gt; /* U1 Format */ constant fixup ConfigEvents = &lt;U2 0&gt; /* U2 Format */ </code></pre> <p>My parse code below. The code can't handle <code>C:\\TMP\\ALARM.LOG</code> (quoted string) here. I don't know how to replace the code "s+([a-zA-Z0-9])+>" to handle both the [a-zA-Z0-9] (0 above) string and the quated string ("C:\TMP\ALARM.LOG" above). </p> <pre><code>$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_XML_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)/) { $name1 = $1; $name2 = $2; $name3 = $3; $name4 = $4; $name5 = $5; $name6 = $6; $name7 = $7; 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"; $x = 1; } } } </code></pre> <p>Thank you for your input.</p> <p>**HELLO ALL,</p> <p>Thanks for so many great solutions. I am a newbew, i would like to do more study based on your post.</p> <p>THANKS A LOT.**</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