in reply to Re^3: Practicing with files
in thread Practicing with files
Gah I'm not so good with explaining but that is what it is doing and I do not want that to happen. All 3 of those words are in 1 file. I want to be able to just type in Grape once and it will remove what I typed in. Right now I can only remove the 3rd line if I type it in 3 times. It's all listed I just want to type it in once no matter which value it is and it will know.
From the snippet above, when I type in grape the "if" only goes through one $_ which the first one is apple.I have to type it in 3 times for it to detect the 3rd $_ which is Grape to even remove it.
elsif (($choice eq "delete") || ($choice eq 2)) { open (STORFILE ,"<", "Storage2.txt") or die "Can not o +pen file\n"; my @storf = <STORFILE>; close (STORFILE); open (my $stor2,">", "Storage2.txt") or die "Can not o +pen file\n"; print "What items would you like to delete?\n"; while (<@storf>) { chomp $_; print ucfirst . "\n"; } my $ans = lc (<STDIN>); chomp $ans; while (<@storf>) { print $stor2 "$_\n" unless /$ans/; } close ($stor2); &stor; }
This one works fine, but that's for just adding and deleting anything into the file.
The snippet on the top, I want to make it read, IF it exist, then do this. BUT it requires more than 1 input till it finally detects what I want to read and remove.
As for the snippet here, I just type it in and it removes what ever it matches
I don't know how else to say it but, for the top snippet I want to type grape only once and read all 3 lines. But since I added the if command it reads only one line ONCE and that is it which is not what I want.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Practicing with files
by GrandFather (Saint) on Apr 02, 2014 at 01:33 UTC | |
by Discipulus (Canon) on Apr 02, 2014 at 08:01 UTC | |
by Jabox (Sexton) on Apr 02, 2014 at 13:09 UTC | |
by Jabox (Sexton) on Apr 02, 2014 at 14:00 UTC |