LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-22-2004, 04:02 PM   #1
KneeLess
Member
 
Registered: May 2003
Distribution: Debian GNU/Linux 3.0 Sid, OpenBSD 3.5
Posts: 190

Rep: Reputation: 30
MD5, opendir, and other problems in Perl...


Okay. I'm just writing a program that produces a list of md5sums for files in a directory. For fun. But it only outputs (from what I can see) the first md5sum. Anyone see a problem with the following code?
Code:
opendir DIR, $tmp;
foreach (readdir DIR)
{      
    next unless(-f && -r);
    open(OUT,">>$file");
    open(FILE,"<$_");
    $md5->addfile(*FILE);
    print OUT $tmp . "/" . $_ . " " . $md5->hexdigest . "\n";
    print $tmp ."/". $_ . " " . $md5->hexdigest . "\n" if $DEBUG;
    close OUT;
    close FILE;
    $md5->new;
}
closedir DIR;
Sample Output:
Code:
/home/sean/perl/srd/scripts/md5.pl~ d41d8cd98f00b204e9800998ecf8427e
/home/sean/perl/srd/scripts/whirlpool~ d41d8cd98f00b204e9800998ecf8427e
/home/sean/perl/srd/scripts/passwd.test d41d8cd98f00b204e9800998ecf8427e
/home/sean/perl/srd/scripts/passwdchk.pl~ d41d8cd98f00b204e9800998ecf8427e
/home/sean/perl/srd/scripts/sneaky.pl d41d8cd98f00b204e9800998ecf8427e

Last edited by KneeLess; 08-22-2004 at 04:22 PM.
 
Old 08-23-2004, 01:07 PM   #2
b0ng
LQ Newbie
 
Registered: Aug 2004
Location: Location??? Where I am is top secret, if I tell you, I have to kill you.
Distribution: College, Slack
Posts: 24

Rep: Reputation: 15
I am playing with it right now, a couple of questions first, what version of perl are you using? I just ran it like 2 seconds ago, and didn't get any type of return.

I am looking at it, I might have to take it home, and run a debugger on it, but give me like a day, and if you still haven't found the problem, pm me, and I will tell you what I found.
 
Old 08-23-2004, 02:15 PM   #3
KneeLess
Member
 
Registered: May 2003
Distribution: Debian GNU/Linux 3.0 Sid, OpenBSD 3.5
Posts: 190

Original Poster
Rep: Reputation: 30
I believe, the problem was that I used $md5->hexdigest twice. I set it to a variable, and called the variable instead of the $md5->hexdigest, and voila! It worked.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ opendir() handling error bendeco13 Programming 1 11-06-2005 02:37 AM
opendir() SIGSEGV on RedHat 9 rylan76 Programming 2 05-26-2004 10:47 AM
Opening a directory WITHOUT using 'opendir' and 'readdir' skywalker27182 Programming 2 11-16-2003 01:32 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
perl opendir like function for php? paulish Programming 2 09-21-2003 03:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration