At 04:37 PM 6/14/05 -0700, you wrote:
>Karyn Williams wrote:
>> Below is code that I found on the web that I slightly modified. I am
>> trying to create a script to remove from a file (tlist) the items in
>> another file (tnames). This works but I have multiple files (tlist) I
>> need to check against. I'm not sure how/where to put the loop and
>> would appreciate any help. I am also wondering why the hash ? Does it
>> work better in the script than an array and what are the keys in
>> this case as the files (both) are just lists of e-mail addresses.
>>
> Are all the files w/in the same directory or scattered? Are there 2 or
> 500?
>
>If only a few, then could create an array which has the filenames:
>
>my @MyTlist = qw (file1 file2 file3 file4);
>Now you could loop off this like:
> foreach my $file2 ( @MyTlist ) {
> open (FILE2, $file2 ) or die "$!";
> while (<file2 >) {
> chomp;
> push @missing,$_ unless (exists($compare{$_}));;
> }
> close(file2 );
> }
>
>Now you can write out all that are not true.
>
>If there are a large number and say in one directory, then use opendir,
readdir to get the files you want and use a simliar setup as above.
>
>Wags ;)
While waiting for replies I maanged to come up with this: which is very
similar to what you have. However see the results below the code. Not so good.
# cat rm_test1.pl
#!/bin/perl
my %compare = ();
open (file1, "/usr/local/tools/tnames") or die "$!";
while (<file1>) {
chomp;
$compare{$_}++;
}
close(file1);
@lists = ("sa-art", "sa-dance");
foreach $list (@lists) {
open (file2, $list) or die "$!";
while (<file2>) {
chomp;
push @missing,$_ unless (exists($compare{$_}));;
}
close(file2);
#print "$_\n" for @missing;
open (file3, ">$list") or die "$!";
print file3 join("\n",@missing);
print file3 ("\n");
close (file3);
}
# cat sa-art
karyn
ador
adam
sue
betty
jerry
# cat sa-dance
karyn
ador
adam
sue
betty
jerry
karyn
ador
adam
sue
betty
jerry
#
So, first question is why is this happenning ? Then how do I fix it ? Also,
there are just a handful of files BUT they are ever changing, so I would
like to not list the statically in the code. Would a
@lists = qw (`ls /usr/local/dir`);
work ?
I have not yet tried Japhy's code. But I have some questions about it I'll
post tomorrow.
>> #!/bin/perl
>>
>> my %compare = ();
>> open (file1, "/usr/local/tools/tnames") or die "$!";
>> while (<file1>) {
>> chomp;
>> $compare{$_}++;
>> }
>> close(file1);
>>
>> open (file2, "/usr/local/tools/tlist") or die "$!";
>> while (<file2>) {
>> chomp;
>> push @missing,$_ unless (exists($compare{$_}));;
>> }
>> close(file2);
>> #print "$_\n" for @missing;
>>
>> open (file3, ">/usr/local/tools/tlist1") or die "$!";
>> print file3 join("\n",@missing);
>> print file3 ("\n");
>> close (file3);
>>
>>
>> TIA
>>
>> --
>>
>> Karyn Williams
>> Network Services Manager
>> California Institute of the Arts
>> [EMAIL PROTECTED]
>> http://www.calarts.edu/network
>
>
>
>*******************************************************
>This message contains information that is confidential
>and proprietary to FedEx Freight or its affiliates.
>It is intended only for the recipient named and for
>the express purpose(s) described therein.
>Any other use is prohibited.
>*******************************************************
>
>
>
--
Karyn Williams
Network Services Manager
California Institute of the Arts
[EMAIL PROTECTED]
http://www.calarts.edu/network
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>