Jump to content

Perl help

Stuff_
Go to solution Solved by Stuff_,

You know, I was working on this problem for a couple of hours. Then immediately after posting here, I had an epiphany. I thought of just shifting the 2nd arg out of the ARGV array, and voila. That worked.

 

I guess I solved my own problem

I'm working on an assignment that I have about 99% complete.

 

Basically, what I am doing is taking the linux command, sha256sum, and printing the message digest of every regular file under any directory given in the file on the command line.

 

for example:

$ mysha <rootfile> [sha256file] 

where rootfile is a file with a directory filename inside and sha256file would be the file being written to. if the file being written to is not specified, print to stdout.

 

I've gotten everything, and I am using the diamond operator to go through my rootfile and run the unix command.

 

My issue is, if I do specify a file (sha256file), the diamond operator tries to run through that, assuming it's another file coming from the command line; which is not correct. So then I get a die message saying "unable to open directory", which makes sense.

 

How can I do this?

This is what my code looks like reading:

 

while (<>) {

  $dir = $_;
  chomp $dir; #remove newline at the end of $dir
  opendir(DIR, $dir) or die "Unable to open directory $_: $!\n";
  @files = readdir DIR;
  closedir(DIR);
}
 
then further down I print the sha. The printing is correct, but how do I get the diamond operator to NOT read my 2nd arg (ARGV[1]) ?
 
Hopefully anybody can help. 
Thanks.
Link to comment
Share on other sites

Link to post
Share on other sites

You know, I was working on this problem for a couple of hours. Then immediately after posting here, I had an epiphany. I thought of just shifting the 2nd arg out of the ARGV array, and voila. That worked.

 

I guess I solved my own problem

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×