in reply to Useless Program
#!/usr/bin/perl -w use strict; open (FILE, "+<users.txt") or die "File not found\n"; #Open the file + in read/write mode flock FILE,2; # It is good practice to lock a file you will write to +. my $name = ''; my $yn = ''; print "Enter your name--> "; chomp ($name = <STDIN>); while (<FILE>) { chomp; if (/^$name/) { print "Your name was already found\n"; exit; } } print "Name not found. Would you like to add it? (y/n)--> "; chomp ($yn = <STDIN>); if ($yn eq 'y') { print FILE "$name\n"; #Since we went through the file we can n +ow print to the end of the file close FILE; #Closing a file will unlock it }else { print "FINE!\n"; ; } print "end.\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Useless Program
by lhoward (Vicar) on Jun 01, 2000 at 17:16 UTC | |
|
RE: Re: Useless Program
by husker (Chaplain) on Jun 02, 2000 at 00:14 UTC | |
|
RE: Re: Useless Program
by cei (Monk) on Jun 01, 2000 at 23:05 UTC |