in reply to Re: "scalar found where operator expected" while printing to a glob ref
in thread "scalar found where operator expected" while printing to a glob ref

I see... So it seems that I picked the wrong piece of code as an example to make my own xml consumer :p
  • Comment on Re^2: "scalar found where operator expected" while printing to a glob ref

Replies are listed 'Best First'.
Re^3: "scalar found where operator expected" while printing to a glob ref
by AnomalousMonk (Archbishop) on Mar 01, 2016 at 18:25 UTC

    Further to Eily's post: Instead of
        print $$self $data;
    try
        print { $$self } $data;
    (untested).


    Give a man a fish:  <%-{-{-{-<

      Yes, the block returning the dereferenced file handle is doing the job.

      Even if it is not very explicit in the documentation, it is suggested in the last paragraph.
Re^3: "scalar found where operator expected" while printing to a glob ref
by Eily (Monsignor) on Mar 02, 2016 at 08:16 UTC

    It does seem so, but I couldn't find that piece of code in XML::SAX::Writer, which is not really surprising since this is a syntax error, not just a warning.

      Well, I've just checked and it is not the actual package code.
      I remember now that I found the example of custom ConsumerInterface in the documentation of XML::SAX::Writer
      sub output { my $self = shift; $$self .= uc shift; }
      and I have adapted it to my needs: replacing the string scalar to store the data by a file handle. Thus I am responsible for print $$self $data;. Actually I was surprised for not having the warning while using the stock module... Mea culpa.

        What line 3 ($$self .= uc shift) is saying (just for those not understanding the above code) is that it dereferences the thingy that $self points to, and appends the upper cased version of the next parameter to thingy, putting the results back into thingy.

        --MidLifeXis