starbolin writes:
This code: push(@{$matchedfiles[$c]}, [ ... ]); Is incorrect. ...
But I don't see a problem with auto-vivification in this case. Consider this test code:
use Data::Dumper;
my @m;
my $c;
$c = 3;
push(@{$m[$c]}, [ 'foo' ]);
$c = 2;
push(@{$m[$c]}, [ 'bar' ]);
print Dumper(\@m), "\n";
for (0..3) {
print "length of m[$_] = ", scalar(@{$m[$_]}), "\n";
}
The first push not only creates $m[3] as an array ref, but also sets $m[0], $m[1] and $m[2] to undef. The second push changes $m[2] from undef to a new array ref.
The last for loop shows that undef is basically indistinguishable from [], i.e. a reference to an empty array.
| [reply] [d/l] [select] |
I didn't say auto-vivification was the problem. I said that using undefined references was his problem. Auto-vivification is saving his butt. He should be using a hash here. Trying to emulate a hash by using a sparse matrix is difficult, error prone and wrong.
In general the code is very poor; the OP uses map when foreach would do, he uses foreach when map or grep is called for, he iterates over an array to create a hash when he could have hashed the data to begin with, he has multiple arrays holding the same data, he uses push when a hash is called for and he uses indexing where a push would serve. Arguing over auto-vivification is akin to rearranging the deck chairs while the ship is sinking.
s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s
|-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,,
$|=1,select$,,$,,$,,1e-1;print;redo}
| [reply] [d/l] |
I'm sure I am not doing this the right way, I'm not a programmer at all, rather an information security professional. We have a need to compare the MD5 value of files to a list of known bad, and I think Perl would be a good way to do it. I'm basically taking it one piece at a time.
1.) Scan the remote system and put all of the filenames and locations into a data set (multidimensional array in this case).
2.) Take that data, and compare to the MD5 list (comma delimited file with "filename,hash value") using the intersect of the two lists of filenames.
3.) I then need to take the list of filenames and their paths (many files have multiple matches but in different directories), and get the MD5 hash of the remote file and compare it to the bad MD5.
4.) If there is a match, somehow identify this and then run a report at the end, or just spit it out to a log file during the match.
You had a nice list of things I did incorrectly, if you would like to provide an outline of how to do this correctly, I'd be happy to restart on the script (it isn't that long). I'll be completing my undergraduate degree at the end of this month and plan to focus on learning Perl and C/C++, so this would be a good learning opportunity for me.
| [reply] |