By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,847 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,847 IT Pros & Developers. It's quick & easy.

Hii I am newbie to perl

P: 3
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
Share this Question
Share on Google+
5 Replies


KevinADC
Expert 2.5K+
P: 4,059
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

P: 3
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
Expert Mod 2.5K+
P: 3,503
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

P: 23
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
P: 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

Post your reply

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