Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Executable and Merging Files 3

Status
Not open for further replies.

CoryMa2c

Technical User
May 31, 2005
10
US
Hello,
I have two questions. The first is pretty easy: How can I make a perl script an executable file for windows so that I wouldn't need to install perl on the computer the script is going to be run?

Second, I need to merge two files together (append). One is pretty large (36 MB) and the other relatively small (2 MB). I just need to append the contents of the second file to the first file. This is what I have so far, but it is running very slowly:

Code:
#!C:\Perl\bin\perl.exe
#Working Directory
$workingdir = "c:\\tmp";
#Log Files
$logfile = "FileInventory.log";
$logfile2 = "FileInventory2.log";

## Open the second logfile and put into an array.

my @merge = ();
open (F3,  "$workingdir\\$logfile2") or die "$!";
while(<F3>){
   chomp;
   push @merge, $_; 
}
close(F3);

## Put each line of the array into the first logfile.

foreach (@merge) {
		chomp $_;
		system "echo $_ >> $workingdir\\$logfile";
};

So, putting the file into the array is very fast. But appending the contents of the array to the other logfile is really, really slow. I am guessing it is because it is making a system call for each line of the file. Any suggestions to speed this up?

Thanks,
- C
 
To convert a perl script into an executable without needing perl installed, go to and look for the PDK which conatins perlapp. They have a trial version which last 30 days from request, but can then be purchased for $145 or $245 depending on which package you buy.

As for the second part, why are you reading into an array when you can just read and append?

Code:
open(O, ">> firstfile.log);
select(O); $| = 1;
open(D, "< secondfile.log");
print O <D>;
close(D);
close(O);


Michael Libeson
 
The PAR module comes with a utility called `pp', which will also bundle a Perl script as an executable. It's totally free, so might be worth checking out first.
 
hmm... maybe I am not getting what you wrote, but it isn't working for me. First, I am guessing you meant to have another quote at the end of firstfile.log:
Code:
open(O, ">> firstfile.log");

But even then, nothing gets appended to firstfile.log. What am I missing?

Thanks,
- C
 
My bad .. that works great. Thanks a ton!!

Code:
#!C:\Perl\bin\perl.exe

#Working Directory
$workingdir = "c:\\tmp";
#Log Files
$logfile = "test1.log";
$logfile2 = "test2.log";

open (O, ">>$workingdir\\$logfile");
select (O); $| = 1;
open (D, "$workingdir\\$logfile2");
print O <D>;
close (O);
close (D);

Out of curiosity, what does this line do?
Code:
$| = 1;
I think I figured out the rest. Thanks again.
- C
 
Sorry about the missing quote.

$| = 1; Turns the buffer off.

Thanks for the star.


Michael Libeson
 
Thanks Michael,
NP. your post made the merge run about 60x faster. :)

Maybe you can help on this too. Now I have a list of files in FileInventory.log, I need to compare that to another file list and then show what is in one and not the other. Right now I am putting the differences into an array and then trying to print the array to a file. I am not having any luck printing the array to a file.
Code:
$workingdir = "c:\\tmp";

my %compare = ();
open (F1, "$workingdir\\BackedUpFiles.txt") or die "$!";
while(<F1>){
   chomp;
   $compare{$_}++;
}
close(F1);

my @missing = ();
open (F2,  "$workingdir\\FileInventory.log") or die "$!";
while(<F2>){
   chomp;
   push @missing,$_ unless (exists($compare{$_}));
}
close(F2);

open (FILE, "$workingdir\\MissingFiles.txt") or die "$!";
print FILE "$_\n" for @missing;
close (FILE);
I have also tried
Code:
foreach (@missing) {
	chomp $_;
	system "echo $_ >> $workingdir\\Missing.txt";
};
This will print to the file, however, I am getting a ton of error messages and it is missing some files. Ideas?

Thanks,
- C
 
PAR - where do you get that from?

Mike

You cannot really appreciate Dilbert unless you've read it in the
original Klingon.

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Code:
open (FILE, "$workingdir\\MissingFiles.txt") or die "$!";

print FILE join("\n", @missing);

close(FILE);
 
Or more accurately,
Code:
open (FILE, "[red]>[/red]$workingdir\\MissingFiles.txt") or die "$!";
original cut & pasted from CoryMa2c's post, which might explain why it doesn't write anything...
 
thx - good stuff

Mike

You cannot really appreciate Dilbert unless you've read it in the
original Klingon.

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
* 4 ish, if Mike's looking for it, must be good gear ;-)

cigless ...
 
I am using the 30 day trial of Perl2exe its been almost 8 months since i installed it, works ok, but it runs a console window, along with the GUI if you have one.

but if your just running it from a command prompt, works very nice! just a little something to look into...
 
Try:

Code:
$workingdir = "c:\\tmp";

my %compare = ();
open(F1, "$workingdir\\BackedUpFiles.txt") || die "$!";
while(<F1>){
   chomp;
   next if (/^\s*$/);
   $compare{"$_"}++;
}
close(F1);

my @missing = ();
open(F2,  "$workingdir\\FileInventory.log") || die "$!";
while(<F2>){
   chomp;
   next if (/^\s*$/);
   if (! defined($compare{"$_"})) {
      push(@missing,"$_");
   }
}
close(F2);

open(FILE, "> $workingdir\\MissingFiles.txt") || die "$!";
print FILE join("\n",@missing), "\n";
close(FILE);


Michael Libeson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top