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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.