Eek! You really *must* wrap your code in <code> and </code> tags to make it readable! Take a gander at the Site How To. Some of your filehandles got 'eaten' (well, aren't displayed, since the browser interprets them as HTML tags it's never seen before).

You seem to have the basic structure down for what you need to do (you could use a DBM file and tie to get your file to behave like a hash, then all you'd have to do is search for a matching hash key and delete that -- but that would be major retooling, suitable for v 2.0 =) Here's one way to do it (that turns on the key field being the first one in the line!):

open OLD, $file or die "Can't open $file:$!\n"; open NEW, ">$file.new" or die "Can't open temp file $file.new: $!\n"; my $found =0; while (<OLD>) { if (/^$username\t/) { $found =1; next; # skips to the next line, so won't print # any matching line to the new file } print NEW; # implicit "$_" } if ($found) { rename ($file, "$file.old") or die "Can't back up old $file: $!\n" +; rename ("$file.new", $file) or die "Can't rename new $file: $!\n"; } else { print "I didn't find $username!\n"; }

HTH.

Philosophy can be made out of anything. Or less -- Jerry A. Fodor


In reply to Re: How to delete a particular record or line from a flat file by taking the name from form input? by arturo
in thread How to delete a particular record or line from a flat file by taking the name from form input? by keshu

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.