toohoo has asked for the wisdom of the Perl Monks concerning the following question:

Hello wise Monks,

I have seached yet but seems not found the relevant thread.

I have an issue in misunderstanding correct work. I have to write some XML using XML::Writer. After all I would like to use, what I have written as string. I get the following error message:

Can't use string .. as a SCALAR ref while "strict refs" in use

a little bit of the code is the following

my $results_xml; my $results_block = XML::Writer->new( OUTPUT => \$re +sults_xml, # .. $results_block->end(); # .. $tempblock = $$results_xml;

Does please anybody have a hint how to solve this?

Thanks in advance, Thomas

Replies are listed 'Best First'.
Re: Can't use string .. as a SCALAR ref while "strict refs" in use
by Anonymous Monk on Jan 23, 2015 at 14:06 UTC

    You give XML::Writer a reference to your variable $results_xml, and it will write its output directly into this variable - you can just say print $results_xml; to see the output. In the code you show, you are attempting to de-reference the variable $results_xml by writing $$results_xml, which isn't possible because $results_xml doesn't contain a reference to another variable, it contains a plain string (your XML). To fix the code you've shown, you could just write: $tempblock = $results_xml; (but without seeing the rest of your code, I'm not sure if you really need to make a copy). See perlreftut and perlref for more information on references.

      Thanks,

      and sorry, it was just a moment of confused mind. Surely it isn't possible to dereference the scalar. Thats just all.

      Thanks again.