Hi,

let's say that I have an object with a definition like:

my $self = { _username => Polo, _user_tags = [], _user_pass => undef }

And I want to save the status of the object like an XML file.

I tried first with:

my $data = $xml->XMLout(%$self , XMLDecl => 1, OutputFile => $xmlf +ile, NoAttr=>1 );

which results in:

Options must be name=>value pairs (odd number supplied) at...

Then I tried

foreach (keys %$self) { $hash->{$_} = $self->{$_}; } my $data = $xml->XMLout($hash , XMLDecl => 1, OutputFile => $xmlfi +le, NoAttr=>1 );

with no luck:

Operation "==": no method found, left argument has no overloaded magic, right argument in overloaded package Net::IP at inc/XML/Simple.pm +line 1406

And afterwards:

$hash->{_username} = $self->{_username} $hash->{_user_tags} = $self->{_user_tags} $hash->{_user_pass} = $self->{_user_pass} my $data = $xml->XMLout($hash , XMLDecl => 1, OutputFile => $xmlfile, +NoAttr=>1 );

and that works as I expected giving the XML I need

And the question is, Why the different behaviour if all the options I tried are basically the same?

Thanks to all monks


In reply to XMLout $self hash by tritt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.