473,320 Members | 2,202 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,320 software developers and data experts.

Hii I am newbie to perl

I am trying to convert an xml file through perl. I want to remove the new line, for example:-

My xml:-
Expand|Select|Wrap|Line Numbers
  1. <bridgehead>
  2. <strong>Exploration and Settlement</strong>
  3. </bridgehead>
  4.  
i want to convert the above xml file as:

<bridgehead><strong>Exploration and Settlement</strong></bridgehead>

my code is :-
Expand|Select|Wrap|Line Numbers
  1. $k =~ s/\n\<[^>]>/\<$1>/g;
  2.  
Please Advice,

srkumar
Jan 9 '08 #1
5 1386
KevinADC
4,059 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. my $xml = q{<bridgehead>
  2. <strong>Exploration and Settlement</strong>
  3. </bridgehead>
  4. };
  5.  
  6. print $xml;
  7.  
  8. $xml =~ s/\n//g;
  9.  
  10. print "\n-------------------\n";
  11. print $xml;
But really it depends on how you are reading the XML lines/document and trying to remove the newlines. Post you current code.
Jan 9 '08 #2
Hi that is an example i have given, i want to remove the newline in the whole XML file.

Please Advice,
srkumar
Jan 9 '08 #3
numberwhun
3,509 Expert Mod 2GB
Hi that is an example i have given, i want to remove the newline in the whole XML file.

Please Advice,
srkumar
Well, to remove a new line, you want to use the chomp() function. You would then have to append your output to a file.

Try doing it, then post your code if it doesn't work and we can help you get it right and learn how to do it.

Regards,

Jeff
Jan 9 '08 #4
I think you can go for using XML::Simple module.
here is the link:
http://search.cpan.org/~grantm/XML-Simple-2.18/lib/XML/Simple.pm

go through the page, you will get an option to format the passed XML file.
read the XML file using XMLin()
and generae new xml file using XMLout()

hope this will help!
Jan 10 '08 #5
savanm
85
test.txt contains
<bridgehead>
<strong>Exploration and Settlement</strong>
</bridgehead>

Expand|Select|Wrap|Line Numbers
  1. open(FILE,"test.txt");
  2. while(<FILE>)
  3. {
  4.  
  5.     $temp=$_;
  6.  
  7.     $temp=~s/\n//sg;
  8.  
  9. }
  10.  
Jan 10 '08 #6

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

Similar topics

0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
2
by: padawanlinuxero | last post by:
Hello all!!! I am learning Perl here at my work, but right now I have a problem, I was reading about DBI, which is very cool since we use a lot of old DBF tables, so I am able to get the DBF...
2
by: drjay | last post by:
I'm trying to get my script to parse a bunch of files and grab data between the <title></> and <blah></> tags. Yes yes, I'm parsing html with regex, it works though. :) The issue I have is...
3
by: aplata | last post by:
I am trying to understand the following code: my @arr1=(5,3,2,1,4); my $i=0; my $j=0; $tmpnum for($i=0;$i<@arr1;$i++) { for($j=0;$j<@arr1;$j++) { if($arr1<$arr1) { ...
3
by: Harlett O'Dowd | last post by:
Please forgive this newbie question but java is new to me and I'm still trying to find a course in my area. I'm tweaking an online survey and have gotten it to display what I want but can't...
3
jenifer
by: jenifer | last post by:
Hi. I'm trying to collapse 2 tables in 1 as follows: table 1 LOC_Os01g01020 1 -1 8174 9019 LOC_Os01g01020 CDS-ANE R02-TIGRv4S1-000003F 2 1 33031 33967 LOC_Os02g01060 33032 33966 FL-AE...
10
by: Mladen Gogala | last post by:
I am a Python newbie who decided to see what that Python fuss is all about. Quite frankly, I am a bit perplexed. After having had few months of experience with Perl (started in 1994 with Perl v4,...
1
by: sixtyfootersdude | last post by:
Good Morning! I am a perl newbie and I think that I am struggling with references. I have an array of references to hashes which I am trying to print. This is what I have: for(my...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.