473,385 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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


Expand|Select|Wrap|Line Numbers
  1.         my $table;
  2.         if(m/<tb>(.*?)<\/tb>/msg)
  3.             {
  4.                 $table = $&;
  5.             }
  6.  
  7.         $table =~ s/\|/<\/ce><ce>/g;    #opening and closing cell
  8.         $table =~ s/<ce>(.+)\n/<ce>$1<\/ce><\/r>\n/g; #for closing row
  9.         $table =~ s/\n(.+)<\/ce>/\n<r><ce>$1<\/ce>/g; #for opening row
  10.  
  11. print OUTFILE $_; # Here is doubt how I can print entire text(output)  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
Oct 29 '07 #1
5 1468
eWish
971 Expert 512MB
Are you trying to get the value of $table into your file?
Oct 30 '07 #2
Dear eWish,

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

Thanks
vishwa Ram
Oct 30 '07 #3
eWish
971 Expert 512MB
Are you slurping the entire file or are you reading it line by line?
Oct 30 '07 #4
Dear eWish

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

Thanks
vishwa Ram
Oct 30 '07 #5
eWish
971 Expert 512MB
If there is HTML code around the text you want then I would use HTML::Parser or HTML::TokeParser::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.
Oct 31 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Pikkel | last post by:
i'm looking for a way to replace special characters with characters without accents, cedilles, etc.
10
by: hokieghal99 | last post by:
import os, string print " " setpath = raw_input("Enter the path: ") def find_replace(setpath): for root, dirs, files in os.walk(setpath): fname = files for fname in files: find =...
9
by: Xah Lee | last post by:
© # -*- coding: utf-8 -*- © # Python © © import sys © © nn = len(sys.argv) © © if not nn==5: © print "error: %s search_text replace_text in_file out_file" % sys.argv
1
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
3
by: alexjaquet | last post by:
Hi, I'm looking for a way to replace some variables for example in perl I do : #replace all $LABEL variables with corresponding values from $SERVER var s/\$LABEL{'(+)'}/ exists $SERVER{$1} ?...
2
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here,...
10
by: Steven W. Orr | last post by:
In the program below, I want this instance to end up calling repmeth whenever inst.m1 is called. As it is now, I get this error: Hello from init inst = <__main__.CC instance at 0x402105ec>...
6
by: patrick.waldo | last post by:
Hi all, I'm analyzing some data that has a lot of country data. What I need to do is sort through this data and output it into an excel doc with summary information. The countries, though,...
1
by: neovantage | last post by:
Hey all, I am using a PHP script which creates headings at run time in a sense at page execution. I am stuck a with a very little problem which i am sure i will have the solution from experts. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.