LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-24-2011, 12:17 PM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Rep: Reputation: 16
for loop to iterate four times, print , then start again


This is an slice from an other wise successful script.
What i need it to do is print one <tr> then print <td>$stat_array</td> fours times, quit print a </tr> then print another <tr> , prints the next four $stat_arrays in @stat_array, and so on and then a </table>.

What it does is print all eight $start_arrays then a </tr>
Code:
my @table_header = ("Process", "Region_Permission","Region Violation","Message Type");
my @stat_array =("ibfarm102  - localtick" ," Greenwich" ," hibmis100 -  procHKHD2 - Hongkong" , "PidMonRsp" ," ibfarm102  - localtick", "Greenwich" ,"hibmis100 -  procHKHD2 - Hongkong", "PidMonReq"         print MAIL "<tr>\n";
     
         for ( $i =0 ; $i <$#table_header ; $i = $i + $#table_header){
         foreach my $stat_array(@stat_array) {
            print MAIL "<td>$stat_array</td>\n";
         }

      print MAIL "</tr>\n";
}
print MAIL "</table>\n";
print MAIL "<br><br>\n";
print MAIL "</table></center></body></html>";
close MAIL;
what i get:
Code:
<tr>
<td>ibfarm102  - localtick </td>
<td> Greenwich</td>
<td> hibmis100 -  procHKHD2 - Hongkong </td>
<td>PidMonRsp</td>
<td>ibfarm102  - localtick </td>
<td> Greenwich</td>
<td> hibmis100 -  procHKHD2 - Hongkong </td>
<td>PidMonReq</td>
</tr>
</table>
<br><br>
</table></center></body></html>
______________

I need the table to look like :
Code:
<tr>
<td>ibfarm102  - localtick </td>
<td> Greenwich</td>
<td> hibmis100 -  procHKHD2 - Hongkong </td>
<td>PidMonRsp</td>
</tr>
<tr>
<td>ibfarm102  - localtick </td>
<td> Greenwich</td>
<td> hibmis100 -  procHKHD2 - Hongkong </td>
<td>PidMonReq</td>
</tr>
 
Old 07-24-2011, 02:19 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Seems like a fairly obvious solution. Each time you get to a count of 4 in the loop throw in the other characters / lines
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] [bash] while loop ..always print the first variable. ridwanfi Programming 5 06-10-2011 08:12 AM
Is there a way to print a range of a char array without a for loop? trist007 Programming 3 11-07-2010 09:15 AM
assigning column name to awk print in a loop bashprog Programming 5 09-29-2010 01:54 AM
shell script :: how to print string that appeared maximum number of times in file ?? mayankmehta83 Linux - Newbie 3 12-07-2009 07:44 AM
Using a for loop to print an interest compounding table guitarstorm Linux - Newbie 4 03-01-2009 11:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration