Probably my fault cause I must be doing something dumb can't seem to find it. I want to count the number of times a file is restarted, this is to do some basic logging on attempts to automate a process, problem is only one value is being recorded in my file counter.txt, I also want errors to be logged if they occur
#!/usr/bin/perl
use win32::OLE qw(in);
$search="Vuser Terminated";
open(INFO, "E:\\Mibor_TimingTest\\Mibor\\output.txt");
@array=<INFO>;
close (INFO);
foreach $line(@array){
if ($line =~ /$search/)
{
print "found $line";
$i=1;
open(COUNT, ">>","c:\\perl\\scripts\\counter.txt")|| die "I cannot ope
+n the file";
print (COUNT "$i");
@array2=<COUNT>;
foreach $line(@array2){
if ($line)
{
print (COUNT "$i++");
close(COUNT);
}
else
{
print "$line \n";
}
}
run_code;
my $error = run_code('c:\\perl\\scripts\\killp.pl');
print "Run code failed, err msg:\n$error" if $error;
#
# add error handling code here for if vugen fails to die..
#
#
#
sub run_code {
$path="c:\\perl\\scripts";
my $path = shift;
open(CODE, $path) || return "Oops: $path $!\n";
local $/;
my $code = <CODE>;
eval $code;
return $@;
}
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.