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

Can can a foreach loop be printed horizontally? 1

Status
Not open for further replies.

bigbalbossa

Programmer
Mar 21, 2002
87
US
Loop:

foreach my $key (sort keys %hash)
{
printf SERVER ("Source: %d\r",$key);
print SERVER ("--------------------\r");
printf SERVER ("Recs with Blank FNAME: %d\r",
$hash{$key}{12});
printf SERVER ("Recs with Blank LNAME: %d\r",
$hash{$key}{25});
print SERVER ("---------------------\r");
}

Output:

Source: 5125
--------------------------
Recs with Blank FNAME: 4
Recs with Blank LNAME: 5
---------------------------
Source: 5135
---------------------------
Recs with Blank FNAME: 0
Recs with Blank LNAME: 0

What I would like to see:

Source: 5125 5135
Recs with Blank FNAME 4 0
Recs with Blank LNAME 5 0

I know there is a way...i just can't get my mind around it :)

Thanks
 
Code:
foreach my $key (sort keys %hash)
  {
     $header.="$key\t";
     $line1.=$hash{$key}{12}."\t";
     $line2.=$hash{$key}{25}."\t";
  }
print $header."\n";
print "=" x 132."\n";
print $line1."\n";
print $line2."\n";
print "=" x 132."\n";
should be enough to work with there, you may need to play with sizes if tabs are too short
HTH


Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
you might want to look into the write() function as well.

- Kevin, perl coder unexceptional!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top