Richard Lee wrote:
what is wrong w/ below program???
use warnings;
use strict;
use diagnostics;
#open 'PASSWD', '<', '/etc/passwd' or die "cannot open: $!\n";
open (PASSWD1, "/etc/passwd") or die "cannot open: $!\n";
my $line;
while ( chomp($line = <PASSWD1>) ) {
The problem is that you are using chomp() in the wrong place. That
should be:
while ( my $line = <PASSWD1> ) {
chomp $line;
print "---$line---\n" if $line =~ /root/;
You are matching the string 'root' anywhere in the string $line. If you
are just trying to match the user 'root' you should anchor the string
like /^root:/.
}
seek(PASSWD1, 0, 0) or die "$!\n";
while(<PASSWD1>) { print if /ellie/;}
Same problem with 'ellie' as with 'root'.
close PASSWD1;
Use of uninitialized value in chomp at ./seek_.pl line 11 (#1)
Or you could do it like this:
#!/usr/bin/perl
use warnings;
use strict;
use diagnostics;
print '---', join( ':', getpwnam 'root' ), "---\n", join( ':', getpwnam
'ellie' ), "\n";
__END__
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/