in reply to Binary Comparision

You're missing a call to binmode(), which is essential for reading and writing binary files under Windows. You're also trying to read a binary file into an array of lines. Binary files don't really have lines, so this won't work. Even if they did, you can't be sure your checker can identify a virus by looking at just one line of a file, so you'll have to be able to match across arbitrary sections of the file.

On a higher level, a virus checker can't really work by loading the entire file into memory - some files you'll have to check won't fit in memory!

-sam

Replies are listed 'Best First'.
Re^2: Binary Comparision
by ikegami (Patriarch) on Feb 28, 2007 at 00:10 UTC

    You're missing a call to binmode(),

    The OP used :raw in the open, a suitable alternative.

    #!perl -l open(my $fh, '<', $0); print(substr(<$fh>, -2) eq "\r\n" ?'bin':'txt'); # txt open(my $fh, '<', $0); binmode($fh); print(substr(<$fh>, -2) eq "\r\n" ?'bin':'txt'); # bin open(my $fh, '<', $0); binmode($fh, ':raw'); print(substr(<$fh>, -2) eq "\r\n" ?'bin':'txt'); # bin open(my $fh, '<:raw', $0); print(substr(<$fh>, -2) eq "\r\n" ?'bin':'txt'); # bin
Re^2: Binary Comparision
by punklrokk (Scribe) on Feb 28, 2007 at 00:02 UTC
    How would I read the file other than into an array? Is there a way to access it a bit at a time? JP

      How would I read the file other than into an array?

      You can read the entire file into a scalar using the following snippet:

      my $raw_data; { local $/; $raw_data = <FH>; }

      Is there a way to access it a bit at a time?

      Yes, using read.

      You can set $/ to a reference to a literal number. Then the file will be read in chunks of that size.

      { local $/ = \1024; while (<$fh>) { # do things with 1k chunks in $_ } }

      After Compline,
      Zaxo