LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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
 
LinkBack Search this Thread
Old 06-02-2008, 02:27 PM   #1
HyperTrey
Member
 
Registered: Sep 2006
Posts: 119

Rep: Reputation: 15
Question How do I printout multiple stdout and headers


I am doing a new project and I know I am probably getting annoying with my seemingly endless amounts of questions. However, if you only knew the huge amounts of answers I have figured out on my own, you would probably be amazed. And of course there is the issue of me not actually ever knowing of perl before I got this job, so I am a pretty fast learner.

I have a script that will write stats of user to an email. We have a header for it and then the format of the STDOUT. What I want to know if we have one set of info, how do I write another set just below that?

IE:

Code:

format HEADER =
Username                  B&W      Color       Total      Total Page Count
--------------------------------------------------------------------------
.

format STDOUT =
@<<<<<<<<<<<<<<<<<<  @######    @######     @####.##       @######
$_,               $BW_amt{$_},  $CL_amt{$_},   $totals{$_},      $tot_page_count{$_},
.







format HEADER2 =
Printer Name              Page Count
--------------------------------------------------------------------------
.

format STDOUT2 =
@<<<<<<<<<<<<<<<<<<  @######    
$printer,             $page count
.

of course I kinda want to have this in one script if possible so I am thinking it may have each in a while loop or something. Would that work and have the STDOUT in a while loop???
 
Old 06-02-2008, 06:42 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
Never used the format word myself, but this looks like a good place: http://www.webreference.com/programming/perl/format/
HTH
 
Old 06-06-2008, 12:58 PM   #3
HyperTrey
Member
 
Registered: Sep 2006
Posts: 119

Original Poster
Rep: Reputation: 15
Question

I have the multiple STDOUT figured however I am running across a new issue. If I am running 2 while loops (
Code:
 while(<>) {
) How do I reset the log file used or keep the 2nd while loop from stalling.

I have one loop that will go through the log file and write to the first STDOUT (name is actually that) and a 2nd while loop that will go through the same lop file and print out different information using the same entries. (one prints out the totals for the users and the 2nd STDOUT, called PRTREPORT, prints out all the totals for the printers and sort them by printer name).
 
Old 06-08-2008, 11:45 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
You've got 2 options;

1. do consecutive loops, opening/closing file within Perl
eg something like
Code:
$f1=shift(@ARGV);
open(LOG,"<", $f1) or die "unable to open $f1: $!\n;
while(defined($rec=<LOG>))
{
    do STDOUT stuff
}
close(LOG) or die "unable to close $f1: $!\n;

open(LOG,"<", $f1) or die "unable to open $f1: $!\n;
while(defined($rec=<LOG>))
{
    do PRTREPORT stuff
}
close(LOG) or die "unable to close $f1: $!\n;
OR
examine each line twice
Code:
while(defined($rec=<>))
{
    do STDOUT stuff
    do PRTREPORT stuff
}
your choice
 
Old 06-09-2008, 08:05 AM   #5
HyperTrey
Member
 
Registered: Sep 2006
Posts: 119

Original Poster
Rep: Reputation: 15
Question

Quote:
Originally Posted by chrism01 View Post
examine each line twice
Code:
while(defined($rec=<>))
{
    do STDOUT stuff
    do PRTREPORT stuff
}
I take it the each line would be a call to a sub? and this will correctly appended the information as I need? I have tried using two separate files and I am having problems with emailing the final output.

[code]
system("$home/bin/user-report /<path>/$f");
system("$home/bin/printer-report /<path>/$f");
[code];

and on the screen it does what it is supposed to do. However, the mother script that calls this script send the output of this file (the one that the 2 lines are from) to an email and only the output of the user-report is shown.
 
Old 06-09-2008, 06:43 PM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
1. Yes
Code:
while(defined($rec=<>))
{
    do STDOUT stuff
    do PRTREPORT stuff
}
becomes
Code:
while(defined($rec=<>))
{
    create_rpt_1($rec);
    create_rpt_2($rec);
}
I'd recommend opening separate output files in each sub, don't use STDOUT as one of the filehandles though.
Then email the resulting files.

2. If you are going to call 2 separate rpt progs via system(), then they should do their own emailing.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Multiple Column Headers rduncan10 Programming 3 08-21-2007 01:24 PM
redirecting stdout to /dev/null and stderr to stdout? Thinking Programming 1 05-18-2006 02:36 AM
c/c++ replacable printout R00ts Programming 8 07-24-2005 08:19 PM
how to redirect stdout [binary stream] to multiple processes vtaminh Linux - General 2 08-19-2004 01:05 PM
can someone help with dmesg printout ? ... purpleburple Linux - General 3 07-30-2002 10:03 PM


All times are GMT -5. The time now is 05:06 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration