On 6/23/07, Tom Phoenix <[EMAIL PROTECTED]> wrote:
> use File::Copy;

Are you actually using File::Copy? I didn't find any call to it in
your posted code.

Sorry, I left it in by mistake. This code is a small part of a very
large program.


> use strict;
> use warnings;

That's good....

> $|=1;           # flush output buffer
> open (FILTERfh, "< filter.in") || die "Can not open filter.in: $!\n";
> open PASSWDfh, '</etc/passwd' or die "Can not open the file: $!\n";
> open PASSWDFILfh, ">passwd.out";

I can't say that I like the style of having filehandle names ending in
"fh", but it's one way to do it.

I din't want to make mistakes, maybe later I change.

The actual program writes to STDOUT as well.


   for my $user (0..$#input) {  # Not 1..$#input, is it?

If that gives me the same result, then it is less typing. I use field
0 for something else.


And, unless you needed an index, you'll be even more likely to get it
correct if you use a foreach directly on the array:

   for my $user (@input) {  # Now $user is the user, not the index

>         print "$input[$user] is being added.\n";
>         while (<PASSWDfh>) {

Now you're reading one file in a loop, inside the loop on FILTERfh. Do
you mean to re-read the password file for every line in the outer
loop's file? That sounds slow, but you could do it.

For each field (user) in the filter.in file, I will have to find the
user in passwd file, wouldn't I need to re-read the passwd file as
much as there are fields in filter.in file?

(You'll either need to reopen the file, or use seek() to get back to the start.)

A better algorithm would read through the entire FILTERfh datastream,
storing away what you'll need. Later, when you read the password file
in a single pass, you can compare the data in memory to the data read
from the file.

I am not sure how much I can read into memory space without affecting
other programs but the entire FILTERfh could be a pretty large. Each
line could have up to 100 fields (users) and there could be 3 or 5
lines. How would I read them into memory? In an array?

Does that get you closer to a solution? Good luck with it!

Hope so. Thanks.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to