Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
What I need to do is to be able to update this file base on the user information let's say I want to delete student so I should be able to delete the whole line that contains the infromation about the student or if I want to only update somthing let's say the age. I am trying to do it by reading the file making the change and copying to another but don't seem to work for me . I am sure there is a better way to update the file than what I am doing .. Can someoen advice? here is an example of what I am doing :stdNum stdNam stdLoc stdAge stdGrd 43 gorge Brazil 28 A 12 John FL 83 B+ 66 Sam Canada 43 C
give me a funki output and doesn't update the file. thanksmy $stdInfo="/home/stdInfo"; print " Enter the number of student that you want to delete\n"; my $std = <STDIN>; open(FILE, "$stdInfo") || die "couldn't open $stdInfo\n"; open(FILECOPY, ">std") || die "couldn't open std\n"; while(<FILE>) { chomp; next if ( $_ =~ /^#/ ); if ($_ =~ /^$std/) {s/$_//;} print FILECOPY; } system ( "mv std $stdInfo" ); close(FILECOPY); close(FILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: updating Input file
by waswas-fng (Curate) on Feb 23, 2004 at 20:58 UTC | |
|
Re: updating Input file
by pzbagel (Chaplain) on Feb 23, 2004 at 21:02 UTC | |
by Anonymous Monk on Feb 23, 2004 at 21:04 UTC | |
|
Re: updating Input file
by ambrus (Abbot) on Feb 23, 2004 at 21:09 UTC | |
by arden (Curate) on Feb 23, 2004 at 21:36 UTC | |
by ambrus (Abbot) on Feb 23, 2004 at 22:55 UTC | |
by Anonymous Monk on Feb 23, 2004 at 23:26 UTC | |
by ambrus (Abbot) on Feb 23, 2004 at 21:42 UTC | |
|
Re: updating Input file
by ambrus (Abbot) on Feb 23, 2004 at 20:50 UTC | |
|
Re: updating Input file
by TomDLux (Vicar) on Feb 24, 2004 at 04:11 UTC |