in reply to sprintf is printing unexepected output

Any time you have a problem like this, make sure you examine your variable closely for non-printable characters. I like doing:
use Data::Dumper; chomp($code = <IFH>); print Data::Dumper->new( [ $code ] )->Terse(1)->Useqq(1)->Dump();

Replies are listed 'Best First'.
Re^2: sprintf is printing unexepected output
by ferreira (Chaplain) on Dec 29, 2006 at 19:28 UTC

    You may also give a try with Data::Dump, which can emit a nice output in the form of a quoted Perl string with less fuss.

    use Data::Dump qw(dump); chomp($code = <IFH>); print dump($code);

    Data::Dumper has the advantage of being in the core, but Data::Dump usually install smoothly from CPAN.

      You want to be careful about Data::Dump, its actually one of the worst serilization modules around. Its relatively trivial to construct a structure that will make Data::Dump extremely unhappy.

      Stick with Data::Dumper, and if you need something easier to read and more powerful and accurate then switch to Data::Dump::Streamer.

      ---
      $world=~s/war/peace/g

        I really didn't know that. In my experiences (which are far from sophisticated), I don't remember a single time I regreted to use Data::Dump. Probably I haven't reached the edges that you mentioned. Given the zero size of the bug queue of the module and the general quality of modules by Gisle Aas, I thought it was quite a robust module. Maybe such examples of intolerance by Data:Dump should be transformed into bugs, so they get a chance of being fixed.

        But it may be possible as well that things changed since the last time you gave a chance to Data::Dump. For instance, in the Changes file, we read:

           Release 1.05
        
           Improved track scalar references; dump() ended up
           recursing forever on some cyclic structures.
        

        On the other hand, the usage we were telling about was as a debugging aid. If it fails, you can backup to Data::Dumper's ugly output without serious consequences.