All I am trying to do is there is a mandatory tag in DCR, and I am trying to read the content of that tag by a basic file reading using perl. I do not want to use any Parser. here is the snippet. Slap me where i am going wrong?This things executing giving me a blank "Value is :"Thanks[html] my $text; open(SAMSUNG, "$dcr_path"); while() { $text .= $_; } close(SAMSUNG); print $text; $text=~/\n*$\//; $text=~m/^\(.*)\<\/item\>$/s; print "Value is : $1";[/html]
Can you tell us what formatting you get in your output? Examples are good.
Here is an example, typical snippet of a DCR is as below.[html] Some Content which goes hereOutput: Some Content which goes here[/html]I was guessing that it is keeping the formatting in the newline for which it is looking for starting with .Thanks
Do you mean to say that you need "Some content which goes here" and not [html]Some Content which goes here[/html]
How about trying:[html] $text =~ m/(.*?)<\/value><\/item>/ims;[/html]
How about getting the formatted string and do substitution for tags?[html]$text =~ s///;[/html]
open(IN, '<:utf8', $file) || die " '$file' ($!)";my $text = do {local $/; <IN>};close(IN);print "$text\n------------\n";$text =~ s/[\r\n]*//gsm;if ($text =~ m|^.*<item name="Title">\s*<value>(.*?)</value>\s*</item>.*$|) { print "Value is: $1\n";}
You'r regex didn't work Adam for some reason, it wan't executing the if condition. here is what i did to get rid of all spaces, except one indentation before the result.
Here is my snippet, [html]$text=~/\n*$\//;$text =~ m/(.*?)<\/item>/ims;my $result = "$1";$result =~s/\//;$result =~s/\<\/value\>//;$result =~s/[\r\n\t]//igm;print "$result";[/html]Thanks
Thank You Adam for taking time to correct me. I will implement all your suggestions, as i said this is small part of a bigger code, the reason I wrote it the way it is that it fits my requirement. I wanted to avoid all this by just using an XML or DCR parser, but the performance issues were debatable against the more generic file parser.either way my code works the way it is supposed to. I am good for now.thank You once again.
use XML::XPath;my $xp = XML::XPath->new(filename => $file);my $nodeset = $xp->find('//item[@name="Title"]');foreach my $node (@{$nodeset}) { (my $v = $node->string_value) =~ s|\n| |gsm; print "V: $v\n";}