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: Regular Expressions:
How to parsing quoted strings in my case.

 



nanohe
New User

Dec 22, 2009, 3:52 AM

Post #1 of 1 (2782 views)
How to parsing quoted strings in my case. Can't Post

        

Hello.

Good day.



Hello.

Good day.

My text file content below. tmp.txt (a very big size file)

Quote
constant fixup private AlarmFileName = <A "C:\\TMP\\ALARM.LOG">

constant fixup ConfigAlarms = <U1 0> /* U1 Format */




My parse code below.


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, ">$dest_xml_file") || die "Coult not open output file $dest_xml_file";

$x = 0;

print DEST_CS_FILE "<!-- from tmp.txt-->\n";
while (<SOURCE_FILE>)
{

&ConstantParseAndPrint;

}

sub ConstantParseAndPrint
{
if ($x == 0)
{

if(/^\s*(constant)\s*(fixup|\/\*fixup\*\/|)\s*(private|)\s*(\w+)\s+=\s+<([a-zA-Z0-9]+)\s+([a-zA-Z0-9])+>\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;
}
}
}


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 quoted string ("C:\TMP\ALARM.LOG" above).



thank you for your input.



(This post was edited by nanohe on Dec 22, 2009, 4:28 AM)

 
 


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

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