Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Remove find tag

by tyce (Initiate)
on Apr 26, 2013 at 07:01 UTC ( [id://1030780]=perlquestion: print w/replies, xml ) Need Help??

tyce has asked for the wisdom of the Perl Monks concerning the following question:

input: <p class="normal">The majority of CA-MRSA strains are sensitive + [<a id="ch1-bid.38" href="#rch1-bid.38">38</a>,<a id="ch1-bid.38" hr +ef="#rch1-bid.39">39</a>]</span>. SXT has [<a id="ch1-bid.101" href=" +#rch1-bid.101">101</a>]</span>). SXT can be considered for use in sel +ected MRSA cases where patients are not tolerant of other, more activ +e, antibiotics.</p> <h3 class="h3t">Rifampicin</h3> ############## open(file,"<chapter01.xml")or die "the Erroer line si $!"; @filelist = <file>; $coutnline=0; $count =0; foreach(@filelist) { # print $_; $tlist= $_; if($tlist =~m/id="ch1-bid.[0-9]+/i) { #print $&."\n"; $mc_line = $&; chomp; if($mc_line =~ s/(?:\s*\b$re)+$//) { print "[$_]\n"; # print "$& test1 \n";; } else { #print "not matched \n"; push(@ovr,$_) } $coutnline++; } else { push(@overlist,$_); # print "the line is over writed \n"; $count++; } } close(file); print $coutnline."\n"; print $count; #out put needs input: <p class="normal">The majority of CA-MRSA strains are sensitive + [<a id="ch1-bid.38" href="#rch1-bid.38">38</a>,<a href="#rch1-bid.38 +">38</a>]</span>. SXT has [<a id="ch1-bid.101" href="#rch1-bid.101">1 +01</a>]</span>). SXT can be considered for use in selected MRSA cases + where patients are not tolerant of other, more active, antibiotics.< +/p> <h3 class="h3t">Rifampicin</h3>
Update
input : <p class="normal">nfection <span class="small">[<a id="ch1-bi +d.1" href="#rch1-bid.1">1</a>]</span>.</p> <p class="normal">nfection <span class="small">[<a id="ch1-bid.2" href +="#rch1-bid.2">2</a>]</span>.</p> <p class="normal">nfection <span class="small">[<a id="ch1-bid.4" href +="#rch1-bid.4">4</a>]</span>.</p> <p class="normal">nfection <span class="small">[<a id="ch1-bid.4" href +="#rch1-bid.4">4</a>]</span>.</p> ----------------------------------- output : <p class="normal">nfection <span class="small">[<a id="ch1-bi +d.1" href="#rch1-bid.1">1</a>]</span>.</p> <p class="normal">nfection <span class="small">[<a id="ch1-bid.2" href +="#rch1-bid.2">2</a>]</span>.</p> <p class="normal">nfection <span class="small">[<a id="ch1-bid.4" href +="#rch1-bid.4">4</a>]</span>.</p> <p class="normal">nfection <span class="small">[<a href="#rch1-bid.4"> +4</a>]</span>.</p> ======end don't want id="ch1-bid.4" tab. pls find

Replies are listed 'Best First'.
Re: find and remove one or more key
by jethro (Monsignor) on Apr 26, 2013 at 07:41 UTC

    The best way to handle xml files is with a module. If you look on CPAN you find some like XML::Simple or XML::Twig

    Also you should change your data type to store your keys. Use a hash instead of an array. Why? Because a hash already makes sure that there no key can be repeated. And searching for a key is a lot faster than with an array.

    If you don't know how to use a hash, read the docs. It is nearly as simple as an array, but sooo much better for most problems

    UPDATE: This is not a code writing service. The script you had was not bad as a first draft. Adapt it a bit, debug it and it should work. Here is a hint:

    #Suppose you got a new XML key and value read from the file in $key an +d $value if (not exists $hash{$key}) { $hash{$key}= $value; } else { #drop key }

    This is already the meat of your hash handling.

Re: find and remove one or more key
by vinoth.ree (Monsignor) on Apr 26, 2013 at 07:05 UTC

    Please tell us what you are trying with this code in words.


    All is well
Re: Remove find tag
by DrHyde (Prior) on Apr 26, 2013 at 10:33 UTC
    What have you tried so far, what did you expect to happen, and how did the results differ from what you expected?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1030780]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-19 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found