There's no reason to be using printf here. print will work just fine. The reason for your error, however, is that the '%' has a special meaning twice. First, it's interpreted as the start of a hash to be interpolated into the string. Your '\' correctly escapes it from this. However, the printf function then does another round of interpolation, and it expects certain codes in the string, which start with '%'. This time, you use the code '%%' to have it print a literal '%'. Your string that you would pass into printf would look like "...\%\%..."

Replies are listed 'Best First'.
(tye)Re: Answer: How do I print a % (percentage sign)?
by tye (Sage) on Dec 06, 2000 at 01:08 UTC

    You are mostly right. However, full hashes are not subject to string interpolation, so there is no need to escape the "%" via "\%". So using "%%" for printf is just fine.

            - tye (but my friends call me "Tye")
Re: Answer: How do I print a % (percentage sign)?
by chipmunk (Parson) on Dec 06, 2000 at 01:05 UTC
    Minor correction: scalars and arrays interpolate inside strings, but hashes don't; %'s do not need to be escaped with a backslash inside double-quoted strings.