How big is the file you need to work with? Can you read the whole thing into memory or could it possibly get too big to do that. Provided the file won't grow too large, you can do something like:
my $stdInfo="/home/stdInfo"; print " Enter the number of student that you want to delete\n"; my $std = <STDIN>; #Don't forget to get rid of the newline character from the input chomp $std; #Open the file and read it in: open(FILE, "$stdInfo") || die "couldn't open $stdInfo for reading"; #Each line is stored in an array my @in=<FILE>; close(FILE); #Now open the same file again for output open (FILE, ">$stdInfo") ||die "couldn't open $stdInfo for writing"; #Now print out everything except what you want to delete: for (@in) { print FILE unless ( $_ =~ /^$std/ ); } close(FILE);
The code is simple and could definitely use a ton of error-checking stuff to make sure the user is input correct input. But I'll leave that up to you.
Later
In reply to Re: updating Input file
by pzbagel
in thread updating Input file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |