Hi ,
I try to combined the code with threads,

but it shows "thread failed to start: Not a CODE reference at D:/Perl/lib/threads.pm" is that any go worse?
use strict; use Win32::ChangeNotify; use Win32::IPC; use File::Basename; use File::Glob; use DBI; use threads; my $path = 'c:\temp\buffer\event'; #$|=1; my @threads; ### Main program part my $notify = Win32::ChangeNotify->new( $path, 0, 'FILE_NAME' ); my %last;@last{ glob $path . '\*' } = (); CHECK_MAIN(); while( 1 ) { $notify->wait; $notify->reset; my @files = glob $path . '\*'; if(@files == scalar keys %last) { my %temp; @temp{ @files } = (); delete @temp{ keys %last }; foreach my $file (keys %temp){ my $currentFile = basename $file; if ($currentFile =~ /\.log$/){ push @threads, async \&READ_FILE($file); # READ_FILE("$file"); } } } undef %last; @last{ @files } = (); } $_->join for @threads; exit 0; sub CHECK_MAIN{ } sub READ_FILE{ my $file = shift; my $pattern; my $errMsg; open(F, "unix.txt")|| die "unix\.txt not found\nopen : $!"; while(<F>){ chomp($_); $pattern .= $_."|"; } close(F); chop($pattern); my (@errlog, @normal) = (); chomp($file); $file =~ s/\\/\//g; sleep 1; open(TARGET, $file) || die "$file not found\nopen : $!"; while (<TARGET>){ if(/$pattern/ig){ next if(/root\-oracle/ig); chomp($_); my $temp = "$&\|".$_; push (@errlog, $temp); }else{ push (@normal, $_); } } close(TARGET) || warn "close : $!"; # print "@errlog"; #SEND_SMS(\@errlog) if(@errlog > 0); #ADD_DATA(\@errlog) if(@errlog > 0); } # END of READ_FILE

In reply to Re^2: create new task from main program by benlaw
in thread create new task from main program by benlaw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.