Nir Cohen wrote: > > I try to write a script that open 2 files . > the first file is /etc/passwd which in the first column has the > users name in my server .the second file is a file that has just users name in each >row. > I want a script that will check both files and if the users name is the same in the >two files the script will print me the whole line from /etc/passwd for this user. > Here is what I did-the problem is that it print me the whole users of /etc/passwd >even those users that are not in the other file. > here is the script: > #!/usr/bin/perl -W
use strict; > open(nir, '/etc/passwd'); You should use caps for file handles and _always_ test the return value of open. open NIR, '/etc/passwd' or die "Cannot open '/etc/passwd': $!"; > while(<nir>) { > ($a, $b, $c, $d, $e, $f, $g, $h) = split(/:/, $_); > open(zvi, '/users/zvikaus/Rad_pine.txt'); See above open ZVI, '/users/zvikaus/Rad_pine.txt' or die "Cannot open '/users/zvikaus/Rad_pine.txt': $!"; > $z=<zvi>; > chomp($z); > if ($z=$a) { > print ("$a\n"); > #print ("$a,$b,$c\n"); > } > close(zvi); > } > close(nir); Anyhow, this is how I would do it: #!/usr/bin/perl -w use strict; my $file = '/users/zvikaus/Rad_pine.txt'; open ZVI, $file or die "Cannot open '$file': $!"; while ( <ZVI> ) { chomp; print "$_\n" if defined getpwnam( $_ ); } close ZVI; __END__ Have a look at the functions getpwent(), getpwnam() and getpwuid(). John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]