in reply to Re^4: problem with sysseek in loop
in thread problem with sysseek in loop

I think you should really take the habit of indenting your code correctly. This code of yours:
my $dirname = "extracted"; open (my $md5file, '<', "C:/md5"); binmode($md5file); foreach my $file (<$dirname/*>) { next if -d $file; open( my $FILE, $file ); binmode($FILE); $file =~ s{.*/}{}; my $md5hash = Digest::MD5->new->addfile($FILE)->hexdigest; if ($md5hash =~ $md5file){ print "$file MATCH\n"; } else { print "$file NO MATCH!\n"; } }
should probably be rewritten more or less this way (no code change, just improved formatting):
my $dirname = "extracted"; open (my $md5file, '<', "C:/md5"); binmode($md5file); foreach my $file (<$dirname/*>) { next if -d $file; open( my $FILE, $file ); binmode($FILE); $file =~ s{.*/}{}; my $md5hash = Digest::MD5->new->addfile($FILE)->hexdigest; if ($md5hash =~ $md5file){ print "$file MATCH\n"; } else { print "$file NO MATCH!\n"; } }
as this would enable you to better visualize the logical structure and detect possible problems or bugs.

Concerning subroutines, yes, by all means, learn them, this is quite easy and necessary. The perlsub document tells you more or less everything about them, but it has probably far more details than what you need or want for a start. For an easier introduction to them, read the relevant section (http://perldoc.perl.org/perlintro.html#Writing-subroutines) of the perlintro document, but don't read only the section on subs, reading the full document would probably be very useful to you.

Replies are listed 'Best First'.
Re^6: problem with sysseek in loop
by james28909 (Deacon) on May 08, 2014 at 15:43 UTC
    Yes i tried this and if(exists and i cannot get it to work like this for some reason, i think i would be better off to just add filename, md5hash, and any other value to a hash.
    My only question then would be, if i printed the filename and md5, would the md5 match the filename?
    ive never used hashes but was told they are great as long as your not worried about the order of the elements in them. all i can do is code it and try :)