in reply to printf x format ?
Perl is not C. Though I occasionally use sprintf in Perl, I rarely use printf, whose doco warns:
Don't fall into the trap of using a printf when a simple print would do. The print is more efficient and less error prone.
Hope the following test program clarifies:
use strict; use warnings; my $ca = 'A'; print "$ca\n"; # outputs A printf "%s\n", $ca; # outputs A printf "%c\n", ord($ca); # outputs A printf "%x\n", ord($ca); # outputs 41 printf "%d\n", ord($ca); # outputs 65
See also: ord, chr, hex, oct, sprintf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: printf x format ? -- solved
by pgmer6809 (Sexton) on Mar 03, 2022 at 03:30 UTC |