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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing elements of an array

Status
Not open for further replies.

keid

Technical User
Aug 8, 2006
22
DE
Hello

I want to print the elements of a big array,in such a way each 10 elements on a line and each elements has a 10 digits space %10d.


thanks alot in advance

Kozhaya




 
What have you tried so far? Post your code, we'll have a look at it...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
foreach $i (@vals) {
print"%10d",$i;
}


I know it does not work in this way, but i need a hint to start with.
 
You want "printf" rather than "print". Maybe something like this:
Code:
my $counter = 0;
for my $i ( @vals ) {
   printf '%10d', $i;
   print "\n" unless ( ++$counter % 10 );
}
print "\n";
 
Thanks alot

that really worked well and it was quick. Many thanks

Kozhaya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top