Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
My script works fine and update the file , however , I don't want to add a duplicte entries in the file so if Sue 22 exists I don't want to add it again , I am checking for that in my script but it is not catching it .--- DATA ---- NAME AGE Sue 22 Sam 34 LUi 43
Ok thanks$|++; use strict; use Fcntl ':flock'; print "Enter new student's name: "; chomp( my $student = <STDIN> ); print "Enter new student's number: "; chomp( my $studentAge = <STDIN> ); open my $fh, '+<', 'students.dat' or die "open failed: $!"; flock $fh, LOCK_EX or die "flock failed: $!"; my $found = 0; while (<$fh>) { $found = 1 if /^\Q$student\E$/i; } print $fh $student ,"\t" , $studentAge ,"\n" unless $found; close $fh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex issue
by matija (Priest) on Feb 27, 2004 at 21:03 UTC | |
by Anonymous Monk on Feb 27, 2004 at 21:35 UTC | |
by optimist (Beadle) on Feb 28, 2004 at 00:46 UTC | |
|
Re: regex issue
by TomDLux (Vicar) on Feb 28, 2004 at 02:13 UTC | |
|
Re: regex issue
by injunjoel (Priest) on Feb 27, 2004 at 21:50 UTC | |
|
Re: regex issue
by esskar (Deacon) on Feb 27, 2004 at 20:54 UTC | |
by matija (Priest) on Feb 27, 2004 at 21:08 UTC | |
by Anonymous Monk on Feb 27, 2004 at 21:00 UTC | |
by Anonymous Monk on Feb 27, 2004 at 21:03 UTC |