View Single Post
Old 11-12-2011, 04:09 AM   PM User | #4
joeDetroit
New Coder

 
Join Date: Nov 2011
Location: Detroit
Posts: 19
Thanks: 2
Thanked 0 Times in 0 Posts
joeDetroit is an unknown quantity at this point
OK.. I tried, but my head is about to explode....

I can't get past the ...while... statement:

Code:
#!/usr/bin/perl
use File::Copy;

$strSearchFor = "unassigned";
$setCount = 0;
$file = "k:/Packages/Packages/MirrorFolder4.1/testlicense.txt";
$backupFile = "k:/Packages/Packages/MirrorFolder4.1/testlicense.txt.bak";
$newFile = "k:/Packages/Packages/MirrorFolder4.1/testlicensetext.txt.";
copy($file,$backupFile) or die "copy failed: $!";

open (LICENSE, "+<$file" ) or die "Cannot open file.";
my %hash;
while (<LICENSE>){
my ($key, $val) = split /" "/;
$hash{$key} .= exists $hash{$key} ? "$val" : $val;
}
print "hash done...";
$_ = <STDIN>;
foreach $key (%hash){
	print "foreach...";
	$_ = <STDIN>;
	while($setCount == 0){
	print "while...";
	$_ = <STDIN>;
		if ($key{%hash} =~ m/$strSearchFor/){
			print "found it...";
			$_ = <STDIN>;
			$key =~ s/$strSearchFor/$ENV{'ComputerName'}/i;
			print "substitued...";
			$_ = <STDIN>;
			$setCount = 1;
			print "setcount 1...";
			$_ = <STDIN>;
			open (NEWLICENSE, ">$newFile") or die "sorry.";
			#print ($setCount);
			print NEWLICENSE (%hash);
			close (NEWLICENSE);
		}	
	}
}
close (LICENSE);

I added some prints and <STDIN>s to see where I was in the code, and I can get to 'print "while..."; ' and the script 'sticks' so to speak. It seems like the 'if...' loop never gets evaluated...

I'm very stuck. Any ideas?

Please?

Don't make me get on my knees... It'll help with banging my head on my desk, but still...

Last edited by joeDetroit; 11-12-2011 at 04:12 AM..
joeDetroit is offline   Reply With Quote