in reply to What is this warning? 'Character in ''c'' format wrapped at ...'

I've not seen it before, but it appears to be related to how ASCII characters are handled with pack. From this bug report, it mentions that error occurs when dealing with non-ASCII characters. The fix was to change from pack "c"... to pack "C".... The pack documentation also hints at this.

The source code that generates this tends to suggest that you may just need to switch your template (of course, that really depends upon what you're trying to do with pack):

case 'C': case 'c': while (len-- > 0) { fromstr = NEXTFROM; switch (datumtype) { case 'C': aint = SvIV(fromstr); if ((aint < 0 || aint > 255) && ckWARN(WARN_PACK)) Perl_warner(aTHX_ WARN_PACK, "Character in \"C\" format wrapped"); achar = aint & 255; sv_catpvn(cat, &achar, sizeof(char)); break; case 'c': aint = SvIV(fromstr); if ((aint < -128 || aint > 127) && ckWARN(WARN_PACK)) Perl_warner(aTHX_ WARN_PACK, "Character in \"c\" format wrapped"); achar = aint & 255; sv_catpvn(cat, &achar, sizeof(char)); break; } } break;

Cheers,
Ovid

New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)

  • Comment on Re: What is this warning? 'Character in ''c'' format wrapped at ...'
  • Download Code

Replies are listed 'Best First'.
Re: Re: What is this warning? 'Character in ''c'' format wrapped at ...'
by halley (Prior) on May 15, 2003 at 20:23 UTC

    Looks like you want 'C' for bytes, and 'c' for (single-byte/ASCII) characters. The output of 'c' is signed while the output of 'C' is unsigned.

    --
    [ e d @ h a l l e y . c c ]

Re: Re: What is this warning? 'Character in ''c'' format wrapped at ...'
by John M. Dlugosz (Monsignor) on May 16, 2003 at 15:02 UTC
    Thanks. So it means that 0xDC is not in the range of a signed byte, but it gives the same 8-bit result anyway.
    perl -e "print (pack('c',0xDC) eq pack('C',0xDC))"
    prints 1.

    I think it's simpler just to say "\xDC", though the pack may be clearer in context, among a list of things of various lengths.

    —John