in reply to XMLout $self hash

It's important to provide sufficient information so that your problem can be reproduced. You have not stated what $xml is. I've assumed this is an XML::Simple object: it could be a subclass of XML::Simple or, indeed, any class providing an XMLout() method. Do let us know if my assumption is wrong! So, my test code (xml_simple_args.pl) starts with:

use strict; use warnings; use XML::Simple; my $xmlfile = q{xml_simple_args.xml}; my $xml = XML::Simple->new();

It's important to post the code you've actually tested. The assignment to $self produces these messages:

$ xml_simple_args.pl Bareword "Polo" not allowed while "strict subs" in use at ./xml_simple +_args.pl line 9. Execution of ./xml_simple_args.pl aborted due to compilation errors.

and after quoting Polo:

$ xml_simple_args.pl Can't modify constant item in scalar assignment at ./xml_simple_args.p +l line 11, near "]," Bareword "_user_tags" not allowed while "strict subs" in use at ./xml_ +simple_args.pl line 9. Execution of ./xml_simple_args.pl aborted due to compilation errors.

My test code uses:

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

I was able to reproduce the first error you posted. The third line of the XML::Simple documentation SYNOPSIS has:

my $xml = XMLout($hashref [, <options>]);

I changed %$self to $self and this worked without error. jethro has provided information about this (above).

I was unable to reproduce your second error: the code you posted worked just fine.

I was unable to reproduce your success with the third version you posted; however, after terminating each statement with a semi-colon, this worked fine as well.

Each successful run produced the same output:

$ cat xml_simple_args.xml <?xml version='1.0' standalone='yes'?> <opt> <_user_pass></_user_pass> <_username>Polo</_username> </opt>

Lessons learned from this exercise:

-- Ken

Replies are listed 'Best First'.
Re^2: XMLout $self hash
by tritt (Novice) on Aug 01, 2011 at 08:58 UTC

    Thanks, your comment made me, finally, realize the error in my code

    First I want to apologize for not posting correct code, but I am unable to disclose the code i am workning with right now

    So, the problem rised when in the object I had..

    sub new { ... $self = { ... _IP => undef, ... } bless ($self, $class); return $self; } sub set_ip { my ($self,$ip) = @_; $self->{_IP} = new Net::IP($ip) or die (Net::IP::Error()); }

    The problem here is that Net::IP does not overload the method '==' so XMLout explodes at line 1406 in Simple.pm.

    if(grep($_ == $ref, @{$self->{_ancestors}}));

    You can see this line is trying to look for references to the present node (circular references)

    So either a) overload '==' at XML::Simple b) Instead of using Net::IP use simple strings c) comment lines 1405 and 1406

    Thanks