Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: updating Input file

by pzbagel (Chaplain)
on Feb 23, 2004 at 21:02 UTC ( [id://331206]=note: print w/replies, xml ) Need Help??


in reply to updating Input file

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

Replies are listed 'Best First'.
Re: Re: updating Input file
by Anonymous Monk on Feb 23, 2004 at 21:04 UTC
    my file contains about 250 line not more than that . Do I need to consider DB or tie with this?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://331206]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-19 04:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found