Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"printf" cannot give output properly

Status
Not open for further replies.

printf

Technical User
Jul 22, 2005
1
IN
printf of perl cannot give output properly when input string
contains % symbol. (The problem has been found in 433 and 500)
For example:
input string="%(File)Arg_1% is not a folder."
after using printf,
output string="%(File)Arg_1 0s not a folder."
detailed info:
------test perl script file: perl_test.pl-----------
#!/usr/bin/perl -sw
local($infile, $outfile)=@ARGV;
print"input:$infile;output:$outfile;\n";
open(IN, "$infile");
open(OUT, ">$outfile");
local($line);
while($line=<IN>){
printf OUT $line;
print &quot;$line&quot;;
}
------------end of perl script file --------------------
-------------test file (input file): perl_bug----------
#example of perl bug
#when perl read the following strings, it cannot print out same string
%(File)Arg_1% is not a folder.
--------------end of test file -------------------------
run it.........
./perl_test.pl perl_bug perl_out
get out put file
--------------output file: perl_ouput--------------------
#example of perl bug
#when perl read the following strings, it cannot print out same string
%(File)Arg_1 0s not a folder.
-------------end of output file---------------------------
 
this isn't really a bug. when using printf() % is a special character pertaining to formats. for example:

printf(&quot;%x&quot;, 255) prints ff.

%x tells printf that you want 255 to be interpreted as a hex number, giving you ff. i assume that since at the second %, since you have nothing after it, perl probably got a little confused and decided you meant 0. so, if you aren't using formats in your code, just use print instead.

 
don't you use %% to print a % using printf?
Mike
michael.j.lacey@ntlworld.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top