Hii I am newbie to perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • srkumar
    New Member
    • Jan 2008
    • 3

    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:-
    [code=xml]
    <bridgehead>
    <strong>Explora tion and Settlement</strong>
    </bridgehead>
    [/code]

    i want to convert the above xml file as:

    <bridgehead><st rong>Exploratio n and Settlement</strong></bridgehead>

    my code is :-
    [code=perl]
    $k =~ s/\n\<[^>]>/\<$1>/g;
    [/code]

    Please Advice,

    srkumar
    Last edited by numberwhun; Jan 9 '08, 12:56 PM. Reason: add code tags
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Code:
    my $xml = q{<bridgehead>
    <strong>Exploration and Settlement</strong>
    </bridgehead>
    };
    
    print $xml;
    
    $xml =~ s/\n//g;
    
    print "\n-------------------\n";
    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.

    Comment

    • srkumar
      New Member
      • Jan 2008
      • 3

      #3
      Hi that is an example i have given, i want to remove the newline in the whole XML file.

      Please Advice,
      srkumar

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        Originally posted by srkumar
        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

        Comment

        • pramodkh
          New Member
          • Nov 2007
          • 23

          #5
          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!

          Comment

          • savanm
            New Member
            • Oct 2006
            • 85

            #6
            test.txt contains
            <bridgehead>
            <strong>Explora tion and Settlement</strong>
            </bridgehead>

            [code=perl]
            open(FILE,"test .txt");
            while(<FILE>)
            {

            $temp=$_;

            $temp=~s/\n//sg;

            }
            [/code]
            Last edited by numberwhun; Jan 10 '08, 02:02 PM. Reason: add code tags

            Comment

            Working...