sprintf and printf in Perl
- From: chen_li3@xxxxxxxxx (Chen Li)
- Date: Thu, 14 Sep 2006 06:44:45 -0700 (PDT)
Hi all,
First of all I want to thank you all for reading and
replying my previous posts.
Now I come across to another problem:
I want to print out a AoA. If I use printf I get what
I expect. If I use sprintf for string I get error
messages but the remaining still look OK. But If use
sprintf also for numbers I get nothing only error
messages. I look at the POD. It looks like sprintf and
printf are changeable to me. Any comments?
Thanks,
Li
#!c:/Perl/bin/perl.exe
use warnings;
use strict;
use Data::Dumper;
my @array=(
['A',1,2,3,4,5,6,7],
['B',1,2,3,4,5,6,7],
['C',1,2,3,4,5,6,7],
);
foreach my $r(@array){
foreach (@$r){
if (/\d+/){printf "%10.2f",$_ ;
}else{printf "%10s",$_;}
}
print "\n";
}
#############################################
Output1 from screen (use printf only and expected)
A 1.00 2.00
B 1.00 2.00
C 1.00 2.00
Output2 from screen (use sprintf for string)
Useless use of sprintf in void context at math9.pl
line 18
1.00 2.00
1.00 2.00
1.00 2.00
Output3 from screen (use sprintf for both)
Useless use of sprintf in void context at math9.pl
line 18.
Useless use of sprintf in void context at math9.pl
line 18.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
.
- Follow-Ups:
- Re: sprintf and printf in Perl
- From: Paul Lalli
- Re: sprintf and printf in Perl
- From: jeffhua
- Re: sprintf and printf in Perl
- Prev by Date: Re: Sum the middle column.
- Next by Date: Re: hash access
- Previous by thread: extracting line between words
- Next by thread: Re: sprintf and printf in Perl
- Index(es):