Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

print to file not working

by grashoper (Monk)
on Apr 20, 2009 at 17:23 UTC ( #758761=perlquestion: print w/replies, xml ) Need Help??

grashoper has asked for the wisdom of the Perl Monks concerning the following question:

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 $@; } } }

Replies are listed 'Best First'.
Re: print to file not working
by ikegami (Patriarch) on Apr 20, 2009 at 17:25 UTC

    Then maybe you should turn on warnings!

    You're reading from a file you've opened for writing.

    open(CODE, "c:\\...\\killp.pl") doesn't execute that file, it opens it for reading. The whole of run_code attempts to replicate do or system.

Re: print to file not working
by Anonymous Monk on Apr 21, 2009 at 06:39 UTC
    | V use win32::OLE qw(in); ^ |
    C:\>perl -e"use win32::OLE qw(in); print in()" Undefined subroutine &main::in called at -e line 1. C:\>perl -e"use Win32::OLE qw(in); print in()" C:\>
      I am looking to capture the output of a log file which is being generated by another process into a new text file,initially I just want to be able to see the errors I am getting, but eventually I will want to be able to parse the file as it is being created for specific error messages. how do I do this will something like this work? taken from example in synopsis from file tail. $name? shouldn't this be defined somewhere?
      use File::Tail; use win32::OLE qw(in); $file=File::Tail->new("E:\\mibor_timingtest\\mibor\\output.txt"); while (defined($line=$file->read)) { print "$line"; } use File::Tail; $file=File::Tail->new(name=>$name, maxinterval=>300, adjustafter=>7) +; while (defined($line=$file->read)) { open(OUT ">>", "c:\\test.txt"); print(OUT "$line"); } sub_do_something{ use win32::OLE qw(in); $search="stuff2searchfor"; open(OUT, "c:\\test.txt"); my @array=<INFO>; close (INFO); foreach $line(@array){ if ($line =~ /$search/) { print "found $line"; sendmail_call_here..to send alert }
        Hello? module names are case-sensitive. win32::OLE doesn't exist

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://758761]
Approved by ELISHEVA
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (1)
As of 2022-01-16 09:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (49 votes). Check out past polls.

    Notices?