473,394 Members | 1,751 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,394 software developers and data experts.

How to generate Log Files for perl code

Hi All,

I have writte a perl code. The perl code simple do some calculation and based on that, it takes a specific action for a device. But i do not have any logging mechanism for this. By this i mean that i do not get any logfile for this. I want to generate a logfile for every step which i write in perl code. For example, if i have i have 2 variables and i am doing the sum, this should be logged in a log file. Can you please help me out of this problem? A sample code will be highly appreciated.

Thanks in advance for your help.

Cheers,
Amit
Aug 20 '07 #1
2 1915
numberwhun
3,509 Expert Mod 2GB
There is no logging mechanism in Perl, that I know of at least, beyond what you put into your code. You will have to not only open a log file (typically to give it a file handle) and then make log entries specific to what you want to see in your log.

For instance, say you are doing the sum of two numbers(as you mention) and you want to see this reflected in your log. You could do something like this:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. open(LOG, ">./logfile.txt");
  7.  
  8. my $var1 = "2";
  9. my $var2 = "2";
  10.  
  11. my $sum = $var1 + $var2;
  12.  
  13. print LOG ("Performed the sum of $var1 and $var2 and received $sum");
  14.  
  15.  
This would put that line into the log file. The only catch is you need to code like this every place you want to capture information for your log.

Regards,

Jeff
Aug 20 '07 #2
Thanks very much Jeff.

Cheers,
Amit
Aug 20 '07 #3

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

Similar topics

3
by: Xah Lee | last post by:
20050226 exercise: generate all possible pairings given a list that is a set partitioned into subsets, generate a list of all possible pairings of elements in any two subset. Example: ...
2
by: shruti | last post by:
hiii all I'm tryin to call a perl script from a C program in following 2 ways- 1.By callin system function. But there's some problem because the system function is not able to executeany...
1
by: shruti | last post by:
hiii all I'm tryin to call a perl script from a C program in following 2 ways- 1.By callin system function. But there's some problem because the system function is not able to executeany...
6
by: jpetrang | last post by:
We use VS6.0 to support our automated build environment, and we'd like to move to something that is currently supported. One aspect of VS6.0 is part of the "Generate Makefile" feature, which it...
5
by: pittendrigh | last post by:
There must be millions of dynamically generated html pages out there now, built by on-the-fly php code (and jsp, perl cgi, asp, etc). Programatic page generation is transparently useful. But...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
1
by: Rahul83 | last post by:
Hi.. I have written a perl script for displaying the difference between two directory structures.(including the diffferences in the files) I have to generate the output in a log file. ...
1
by: Dave | last post by:
So far, I have done all of my programming for PowerPoint addins in VBA. I have created one small class in Perl, which my addin code accesses through a .dll which is registered using regsvr32. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.