473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Print to a file instead of to the screen

I have the following code that prints to the screen but I want to print the lines to a file that I give as an argument to the script instead...

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4.  
  5.  
  6. ####################################################################
  7. # constants
  8. ####################################################################
  9.  
  10. use constant COUNT   => 0;
  11. use constant MAX     => 1;
  12. use constant MIN     => 2;
  13. use constant TOTAL   => 3;
  14. use constant AVERAGE => 4;
  15. use constant FCOUNT   => 5;
  16. use constant FMAX   => 6;
  17. use constant FMIN   => 7;
  18. use constant FTOTAL  => 8;
  19. use constant FAVERAGE   => 9;
  20.  
  21. ####################################################################
  22. # genreport
  23. ####################################################################
  24.  
  25. sub genreport {
  26.    my ($logfile, $reportfile) = @_;
  27.    my ($line, $elapsed, $facade, %calls);
  28.    my (@fields, $count, $min, $max, $total, $average,$fcount,$fmin,$fmax,$ftotal,$faverage);
  29.    my (@list, $totalcalls);
  30.    my ($falseflag);
  31.    my ($statdate,$server);
  32.    my ($starttime,$error,$first);
  33.  
  34.    open(LOGFILE, "<$logfile")
  35.       or die "Can't open $logfile: $!";
  36.  
  37.    open(REPORTFILE, ">$reportfile")
  38.       or die "Can't open $reportfile: $!";
  39.  
  40.    $totalcalls = 0;
  41.    while ($line = <LOGFILE>) {
  42.       chomp $line;
  43.       $falseflag= 0;
  44.       $statdate = substr($line,1,8);
  45.       $starttime = substr($line,9,12);
  46.       if($line =~ (/J2CA0027E/))
  47.        {
  48.        $falseflag = 1;
  49.        while ($line =<LOGFILE>){
  50.         if(($line =~(/_TH/)) || ($line =~ (/invokeMessageEndpointMethod/))) {
  51.          $line = substr($line,3,length($line));
  52.          printf "%s %s,%s\n",$statdate,$starttime,$line;
  53.          last;
  54.         }
  55.       }
  56.     }
  57.  }
  58. }
  59. ####################################################################
  60. # main
  61. ####################################################################
  62.  
  63. if (@ARGV != 2) {
  64.    die "usage: servercalls.pl <logfile> <reportfile>";
  65. }
  66.  
  67. my ($logfile, $reportfile) = @ARGV;
  68.  
  69. genreport($logfile, $reportfile);
  70.  
  71.  
Sep 2 '09 #1
2 2275
numberwhun
3,509 Expert Mod 2GB
@joeferns79
The problem I see is that you open the reportfile for writing, but you never reference the filehandle in the print statement. If you want the print statement to go to file, then it would have to look like this:

Expand|Select|Wrap|Line Numbers
  1. printf REPORTFILE "%s %s,%s\n",$statdate,$starttime,$line;
  2.  
Regards,

Jeff
Sep 2 '09 #2
Thanks, Jeff. Don't know how I missed that.
Sep 3 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Manfred Schwab | last post by:
Recording messages and print statements in a textfile during program execution. Is there a similar command to redirect errormessages or print statements into a standart asciifile during...
2
by: Yaron Cohen | last post by:
Hi, I would like to ask for your help. I am using IE5.5. I have a wide page with horizontal scroll bar. The problem is that I get only 1 page when printing it using "file->print" or...
48
by: David J Patrick | last post by:
I'm trying to rewrite the CSS used in http://s92415866.onlinehome.us/files/ScreenplayCSSv2.html. using the w3.org paged media standards as described at http://www.w3.org/TR/REC-CSS2/page.html ...
1
by: BELIUS | last post by:
Hi all, I am implementing a "Print this Page" function in my ASP.NET application. This function should print a part of the page and I would like to use an MSDN Style "Print this Page". I'm...
7
by: Ron | last post by:
Hi All, Is it possible to have Access print a report, identical to one that would print to a printer, only print to a "standard" text file? I can't find it in help and when I try to just print...
1
by: stcalixte | last post by:
First off, I really don't know much about Access, so please bear with me. Here's my problem. I have an Access file containing about 15 columns and 600 rows. Each cell in one of the columns...
3
by: Max58kl | last post by:
Trying to access data and print it to the screen using Perl Builders I/O Window -------------------------------------------------------------------------------- Hi I am using a program called...
5
by: bdy120602 | last post by:
Is it possible, when a user or viewer of your Web page, prints or takes a screen shot of a Web page with mousover (roll-over) text in it, to have that text printed or captures as part of the screen...
10
by: Ed Jay | last post by:
I do not want to load two style sheets for screen and print media. I'm having difficulty grasping the use of the @print statement, or its syntax. Would someone please provide a simple explanation....
16
by: raylopez99 | last post by:
I am running out of printing paper trying to debug this...it has to be trivial, but I cannot figure it out--can you? Why am I not printing text, but just the initial string "howdy"? On the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.