How to replace particular region only and print all content as a output file.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vishwa Ram
    New Member
    • May 2007
    • 30

    How to replace particular region only and print all content as a output file.

    Hi all,

    I want to replace a particular blocks only not in entire file. But I will give a new output file with replacement. Replacement should not affect other text


    Code:
    		my $table;
    		if(m/<tb>(.*?)<\/tb>/msg)
    			{
    				$table = $&;
    			}
    
    		$table =~ s/\|/<\/ce><ce>/g;	#opening and closing cell
    		$table =~ s/<ce>(.+)\n/<ce>$1<\/ce><\/r>\n/g; #for closing row
    		$table =~ s/\n(.+)<\/ce>/\n<r><ce>$1<\/ce>/g; #for opening row
    
    print OUTFILE $_; # Here is doubt [B]how I can print entire text(output) [/B] from source but with replement in block.

    Input file:

    Some other text
    <tb>
    Het blijvend beeld der Hollandse Kunst|1
    De Bijbel in Holland's Schilder-cultuur|25
    </tb>
    Some other text

    Output file:

    Some other text
    <tb>
    <r><ce>Het blijvend beeld der Hollandse Kunst</ce><ce>1</ce></r>
    </tb>
    Some other text

    Thank in advance.
    vishwa Ramkumar
    Last edited by vishwa Ram; Oct 29 '07, 06:32 AM. Reason: understanding
  • eWish
    Recognized Expert Contributor
    • Jul 2007
    • 973

    #2
    Are you trying to get the value of $table into your file?

    Comment

    • vishwa Ram
      New Member
      • May 2007
      • 30

      #3
      Dear eWish,

      Yes. The output file content is the same order of input file.

      Thanks
      vishwa Ram

      Comment

      • eWish
        Recognized Expert Contributor
        • Jul 2007
        • 973

        #4
        Are you slurping the entire file or are you reading it line by line?

        Comment

        • vishwa Ram
          New Member
          • May 2007
          • 30

          #5
          Dear eWish

          I am slurping the entire file as a single line using undef $/="";

          Thanks
          vishwa Ram

          Comment

          • eWish
            Recognized Expert Contributor
            • Jul 2007
            • 973

            #6
            If there is HTML code around the text you want then I would use HTML::Parser or HTML::TokeParse r::Simple from CPAN to get the content. Then change manipulate the text how you want it then write it to a new file.

            If it is XML then search for an XML Parser and do the same.

            Comment

            Working...