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

Hello.. I have a Mobile agents framework..so I am sending an agent from linux machine to windows.. this is the code of the agent which I am sending
use File::Tail; $|++; open FH, "<rules.txt"; @rules=<FH>; close FH; $name="C:\\users\\Mizo\\desktop\\log.txt; $file=File::Tail->new(name=>$name, maxinterval=>1,interval=>1, adjust +after=>1); while (defined($line=$file->read)) { for (@rules) { $rule=$_; if($line=~/^Request:($rules)/i){ print "$line"; } }
it's goin go transfare from linux to windows and monitors the log.txt file and match the content with rules.txt file which is linux.. the problem is i can't match the file in linux is there a possible way to send the rules.txt file with the agent code? and how? or is there any possible way to do this job

Replies are listed 'Best First'.
Re: Matching between files in different machine..?
by Bloodnok (Vicar) on Apr 10, 2009 at 12:01 UTC
    Hmmm ,

    I think using strictures (use warnings; use strict;) would have undoubtedly helped you here, since between them they'd have pointed out that $rules is undefined in the regular expression i.e. in your snippet

    if($line=~/^Request:($rules)/i){
    should, I think, read
    if($line=~/^Request:($rule)/i){

    Also note that

    foreach (@rules ) { $rule = $_;
    is better written as ...
    foreach my $rule (@rules)
    Moreover, given that the action is the same for every matched rule, I'd modify your snippet to read
    use warnings; use strict; use autodie; use File::Tail; local $|++; open FH, "<rules.txt"; my $rules_re = join '|', <FH>; close FH; $name="C:\\users\\Mizo\\desktop\\log.txt; $file=File::Tail->new(name=>$name, maxinterval=>1,interval=>1, adjusta +fter=>1); while (defined($line=$file->read())) { print $line if ($line=~/^Request:($rules_re)/i); }

    Update:

    Added suggested modifications ,p>

    A user level that continues to overstate my experience :-))
Re: Matching between files in different machine..?
by almut (Canon) on Apr 10, 2009 at 11:56 UTC
    is there a possible way to send the rules.txt file with the agent code?

    Not really sure I understand what you mean, but maybe you want something like

    ... my @rules = <DATA>; ... __DATA__ your rules here ...

    (the __DATA__ section would be at the end of the script, after the code — see "Special Literals" in perldata)

    I.e., with a __DATA__ line in place like this, you could simply append the contents of rules.txt to the script code, before sending it... (I'm assuming the rules are somehow changing more often than the script itself, or some such, otherwise you could have coded them right into the script)