473,657 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Print to a file instead of to the screen

37 New Member
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 2281
numberwhun
3,509 Recognized Expert Moderator Specialist
@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
joeferns79
37 New Member
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
2401
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 programm execution. I would like to echo the complete console output into a textfile and send this file as email at a certain point in time. The programm execution shall not be stopped.
2
8364
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 "window.print".
48
8655
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 The ScreenplayCSS is flawed, for several reasons; -overuse of <div id= tags -doesn't scale screen resolutions (convert from px to in, pt ?) -no media="print" (how much coule be shared between "screen" & "print") -no automatic page breaks (with...
1
2292
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 going to explain what I would like to do. Clicking on the print button I would like to show immediately the print dialog without open a new window with the text formatted for printing.
7
2628
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 to a file (in the printer selection screen of the print routines) it gives me a file named what I wanted, but is just garbage. Can't read it. TIA ron
1
1422
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 contains an email, including all the html coding. Most email have just a few lines of actual text, but with all the html stuff (<doctype><body bgColor></Div><Bodyetc.), it usually fills up most of the screen. Problem is, whenever the content of a...
3
2327
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 Perl Builder which is an Integrated Development Environment for Perl scripting. I am trying to access the data in a txt file and then print the results to the screen. The procedure for doing this is write a script then click on the Run button,...
5
3427
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 shot? If so, how? Thanks,
10
2764
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. For example... If I have a style sheet specifying media="all," is the following correct syntax to center text for printing, but not for screen presentation? ..divClass1 {
16
4514
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 screen, when I open a file, the entire contents of the file is in fact being shown...so why can't I print it later? All of this code I am getting from a book (Chris Sells) and the net. The solution is to be found in the fact that stringbuilder is...
0
8394
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8306
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6164
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.