Ok, not a bad start. However you really, really, really should use strictures: use strict; use warnings;

The first problem is that you have provided a directory path string wiht \ characters - in Perl, as in C, those are quote characters and turn the following character into something magical. To get a single \ you need to "quote" it: \\. use strict; would generate the warning: "Unrecognised escape \d passed through".

The next problem is that /\s(\.){3}.*?)$/ has an extra ) in it. Again strictures would have picked that up for you.

After that, and having declared your various variables using my, all the static errors are cleaned up. What happens when you run? Now the warnings kick in. The first one is "Unrecognized escape \E passed through in regex; ...". You need to quote the file name that is interpolated directly into the regex: /^\Q$fname\E/i

Fix that and run again. The next warning is "... Use of uninitialized value in pattern match (m//) ...". Now there is a logic problem reveiled - what happens if the file name doesn't match? (In this case because of a trailing end of line character.) Fix that by changing the first if to skip if no match: next if $_ !~ /^\Q$fname\E/i;.

Ok, run again - runs with no errors or warnings, that's good. Doesn't produce any output, that's bad. At this point I give up because the file name being matched (C:\\EITV10CMD\\base\\detection\\basic_detection\\Filename\\DOIFFILE.COM) doesn't match any of the data lines. As A quick test I change the file name to something that will match and run again. Still no output.

Set a breakpoint and trace through with the debugger. Heh, that pesky regex we got the warning about is wrong. I didn't the comment and just removed the "extra" ). What it should look like is /\s\.{3}\s(.*)/. Fix that, run again, now we get some output

use strict; use warnings; my $fname = "C:\\EITV10CM\\base\\repair\\Companion_Repair\\File2SelfEx +t\\F2SEXT.COM"; while (<DATA>) { chomp; my $found; next if $_ !~ /^\Q$fname\E/i; chomp($_); /\s\.{3}\s(.*)/; #Trying to extract everthing after ... $found = $1; if ($found eq "is OK.") { my $virusname = "OK"; print "The virus detection name is $virusname\n"; } if ($found =~ /^Found: (.*?) NOT a virus[.]/) { my $virusname = $1; print "The virus detection name is $virusname\n"; } elsif ($found =~ /^Found the (.*?) (virus|trojan) !!!/) { my $virusname = $1; print "The virus detection names is $virusname\n"; #exit(); } elsif ($found =~ /^Found potentially unwanted program (.*?)[.]/) { my $virusname = $1; print "PuPs $virusname \n"; } elsif ($found =~ /Found (virus or variant|application) (.*?)( !!!| +[.])/) { my $virusname = $2; print "virus or variant $virusname \n \n"; } } __DATA__ C:\EITV10CM\base\repair\Companion_Repair\File2File\F2F.COM ... is OK. C:\EITV10CM\base\repair\Companion_Repair\File2SelfExt\F2SEXT.CMP ... i +s OK. C:\EITV10CM\base\repair\Companion_Repair\File2SelfExt\F2SEXT.COM ... F +ound the CMPAN/File2SelfExt virus !!! The virus has been removed from the file. Checking for another virus in the file ... C:\EITV10CM\base\repair\Companion_Repair\File2SelfExt\F2SEXT.COM ... i +s OK. C:\EITV10CM\base\repair\Companion_Repair\File2SelfFile\F2SFILE.COM ... + Found the CMPAN/FIle2SelfFile virus !!! The virus has been removed from the file. Checking for another virus in the file ... C:\EITV10CM\base\repair\Companion_Repair\File2SelfFile\F2SFILE.COM ... + is OK.

prints:

The virus detection names is CMPAN/File2SelfExt The virus detection name is OK

DWIM is Perl's answer to Gödel

In reply to Re: Matching and extracting from file. by GrandFather
in thread Matching and extracting from file. by nisha

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.