Hello,
I'm using XML::Simple to save the content of some hashes uesd by a CGI Perl application.
I'm on a XP OS ($^O = MSWin32). But the same application will need to run under Linux as well.
Basically, I have "sessions" with parameters acquired from HTML pages (textfields, filefields, checkboxes, ...) and other processes, that I manage through hashes. At the end of one session, I save these hashes with XMLout. Then I can read the information with XMLin to restore previous sessions.
Everything works fine with this module, until I save the content of a textfield that has multiple lines.
Say I insert in the textbox some data like this, with a carriage return from the keyboard at the end of each line:
1 3 station_a.txt
1 23 station_b.txt
1 23 station_c.txt
...
I get content of the textbox with something like:
$meteo{data} = $q->param('data');
then I save the hash with:
XMLout(\%meteo,outputfile=>$myroot.'/meteo.xml');
The meteo.xml file, viewed with vi will will be:
<opt data="1 3 station_a.txt^M
1 23 station_b.txt^M
1 23 station_c.txt^M
" />
If I later read the file into the hash with:
%meteo = %{ XMLin($myroot.'/meteo.xml') };
and I initialise the textfield, then carriage return is lost and the data in the textfield are all on the same line:
1 3 station_a.txt 1 23 station_b.txt 1 23 station_c.txt ...
I've tried with
$meteo{data} =~ s/\015?\012/\n/g; # PAG. 623 of Programming Perl
but it does nothing. So I guess that XMLin removes both ^M and newline before filling
$meteo{data}.
Does anybody can suggest me how to deal with this?
Thank you in advance.
Roberto