<div dir="ltr">Hi,<br><br>I need to convert data from xml to csv format, the data is in Hebrew.<br>I tried to do it with extracting the data by my own code and it worked, but when i try to write it to a file every variable gets a new line, even when chomping the data right before printing it to a file.<br>
<br>Here is the code:<br><br>use warnings;<br>use strict;<br>use LWP::UserAgent;<br>use utf8;<br><br>open my $source, &quot;&lt;&quot;, &quot;/home/moshe/perl/work/moreshet.xml&quot; or die &quot;can&#39;t read file &#39;moreshet&#39;: $! &quot;;<br>
open my $file, &quot;&gt;&quot;, &quot;/home/moshe/perl/work/file.txt&quot; or die &quot;can&#39;t write file &#39;file.txt&#39;: $! &quot;;<br>my $line;<br><br>my ( @links, $country, $topic, $description, $lang, $type, $mordesc, $level, $note, @items );<br>
<br>my $i = 1;<br>#my $ua = LWP::UserAgent-&gt;new;<br>#$ua-&gt;timeout(10);<br>#$ua-&gt;env_proxy;<br><br>my @header = ( &#39;country&#39;, &#39;topic&#39;, &#39;description&#39;, &#39;language&#39;, &#39;type&#39;, &#39;sub description&#39;, &#39;level&#39;, &#39;note&#39;, &#39;item&#39; );<br>
<br>while ( my $entry = &lt;$source&gt; ) {<br>    chomp $entry;<br>    if ( $entry =~ /&lt;record_country&gt;/ ) {<br>        $entry =~ s/\s+\&lt;record_country\&gt;//;<br>        $entry =~ s/\&lt;\/record_country\&gt;//;<br>
        $country = &quot;$entry&quot;;<br>    }<br>    if ( $entry =~ /&lt;record_topic&gt;/ ) {<br>        $entry =~ s/\s+\&lt;record_topic\&gt;//;<br>        $entry =~ s/\&lt;\/record_topic\&gt;//;<br>        $topic = &quot;$entry&quot;;<br>
    }<br>    if ( $entry =~ /&lt;description&gt;/ ) {<br>        $entry =~ s/\s+\&lt;description\&gt;//;<br>        $entry =~ s/\&lt;\/description\&gt;//;<br>        $description = &quot;$entry&quot;;<br>    }<br>    if ( $entry =~ /&lt;lang id=&quot;/ ) {<br>
        $entry =~ s/\s+&lt;lang id=&quot;\w\w&quot;&gt;//;<br>        $entry =~ s/\&lt;\/lang\&gt;//;<br>        $lang = &quot;$entry&quot;;<br>    }<br>    if ( $entry =~ /&lt;type id=&quot;/ ) {<br>        $entry =~ s/\s+&lt;type id=&quot;\w+&quot;&gt;//;<br>
        $entry =~ s/\&lt;\/type\&gt;//;<br>        $type = &quot;$entry&quot;;<br>    }<br>    if ( $entry =~ /&lt;sub_description&gt;/ ) {<br>        $entry =~ s/\s+\&lt;sub_description&gt;//;<br>        $entry =~ s/\&lt;\/sub_description\&gt;//;<br>
        $mordesc = &quot;$entry&quot;;<br>    }<br>    if ( $entry =~ /&lt;level&gt;/ ) {<br>        $entry =~ s/\s+\&lt;level&gt;//;<br>        $entry =~ s/\&lt;\/level\&gt;//;<br>        $level = &quot;$entry&quot;;<br>
    }<br>    if ( $entry =~ /&lt;note&gt;/ ) {<br>        $entry =~ s/\s+\&lt;note&gt;//;<br>        $entry =~ s/\&lt;\/note\&gt;//;<br>        $note = &quot;$entry&quot;;<br>    }<br>    if ( $entry =~ /\&lt;item/ ) {<br>
        $entry =~ s/\s+\&lt;item id\=\&quot;\d?\d\&quot; source\=\&quot;//;<br>        $entry =~ s/\&lt;\/item\&gt;//;<br>        my @item = split /\&quot;\&gt;/, $entry;<br>#        my $response = $ua-&gt;get(&quot;$entry&quot;);<br>
        push @links, $item[0];  # or whatever<br>        push @items, $item[1];<br>    }<br>    if ( $entry =~ /\&lt;\/record/ ) {<br>        chomp $country;<br>        chomp $topic;<br>        chomp $description;<br>        chomp $lang;<br>
        chomp $type;<br>        chomp $mordesc;<br>        chomp $level;<br>        print $file &quot;$country,$topic,$description,$lang,$type,$mordesc,$level,@items,@links\n&quot;;<br>        print &quot;$country,$topic,$description,$lang,$type,$mordesc,$level,&quot;, @items, &quot;,&quot;, @links, &quot;\n&quot;;<br>
        @links = &quot;&quot;;<br>        @items = &quot;&quot;;<br>    }<br>}<br><br>close $file;<br><br>Do you have an idea why this is not working?<br><br>Moshe<br></div>