Good day Everyone!

I need help again, the problem was similar to Push,pop, and splice!

This time I wanted to make it work with a "storage.txt" file and a "inventory.txt" file.

My practice is a mess again :D

open (FILE, ">>Storage.txt") or die "Can not open file\n"; flock(FILE,2); my %sfi = <FILE>; print "Would you like to add or delete items for the Storage?\ +n"; print "1. Add\n", "2. Delete\n", "3. Back\n", "4. List\n", "5. Cancel\n"; my $choice = lc(<STDIN>); chomp $choice; if (($choice eq "add") || ($choice eq 1)) { print "What items would you like to add?\n"; my $ans = lc(<STDIN>); chomp $ans; print FILE "$ans\n"; print "The storage contains the following\n"; foreach my $sfi (%sfi) { print "$sfi\n"; } &stor; } elsif (($choice eq "delete") || ($choice eq 2)) { print "What items would you like to delete?\n"; my $ans = lc (<STDIN>); chomp $ans; my @find = grep {$_ =~ $ans} %sfi; if (exists %sfi {my $find = @find?? << not sure how to + do this part too}) { delete {$ans}; print "The storage contains the following\n"; foreach my $sfi (%sfi) { print "$sfi\n"; } &stor; }

I got a feeling someone might already face palm as soon as you see this but what I'm trying to do was to remove any words that contains any of the STDIN for the delete section.

I am also unsure if that was how I set a file to equals a hash so it can do what I was trying to do up there :)

Thank you all in advance! And the post I linked really helped my last practice :D


In reply to Deleting a word in a file! by Jabox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.