Re: what is wrong w/ this program? (getting undefined value.. but I don't understand) please help
John W. Krahn wrote: 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 Thank you for through explanation John as always!! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: what is wrong w/ this program? (getting undefined value.. but I don't understand) please help
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 = ) ) { The problem is that you are using chomp() in the wrong place. That should be: while ( my $line = ) { 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() { 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/
Re: what is wrong w/ this program? (getting undefined value.. but I don't understand) please help
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 = ) ) { print "---$line---\n" if $line =~ /root/; } seek(PASSWD1, 0, 0) or die "$!\n"; while() { print if /ellie/;} close PASSWD1; Use of uninitialized value in chomp at ./seek_.pl line 11 (#1) (W uninitialized) An undefined value was used as if it were already defined. It was interpreted as a "" or a 0, but maybe it was a mistake. To suppress this warning assign a defined value to your variables. To help you figure out what was undefined, perl tells you what operation you used the undefined value in. Note, however, that perl optimizes your program and the operation displayed in the warning may not necessarily appear literally in your program. For example, "that $foo" is usually optimized into "that " . $foo, and the warning will refer to the concatenation (.) operator, even though there is no . in your program. I found the problem. this new fedora 9 I guess hides the /etc/passwd file & is empty file. Sorry for the trouble guys. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
what is wrong w/ this program? (getting undefined value.. but I don't understand) please help
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 = ) ) { print "---$line---\n" if $line =~ /root/; } seek(PASSWD1, 0, 0) or die "$!\n"; while() { print if /ellie/;} close PASSWD1; Use of uninitialized value in chomp at ./seek_.pl line 11 (#1) (W uninitialized) An undefined value was used as if it were already defined. It was interpreted as a "" or a 0, but maybe it was a mistake. To suppress this warning assign a defined value to your variables. To help you figure out what was undefined, perl tells you what operation you used the undefined value in. Note, however, that perl optimizes your program and the operation displayed in the warning may not necessarily appear literally in your program. For example, "that $foo" is usually optimized into "that " . $foo, and the warning will refer to the concatenation (.) operator, even though there is no . in your program. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/