#!/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";
In reply to Re: Useless Program
by c-era
in thread Useless Program
by HeavensTrash
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |