Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
P is for Practical
 
PerlMonks  

Re: Check For Dupes In FLat DB Before Adding

by nedals (Deacon)
on Dec 14, 2005 at 21:52 UTC ( [id://516835]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Check For Dupes In FLat DB Before Adding

If the file is not too big....
my $found = 0; open(FH, "$filename") || die "Cannot open $filename for reading: $!\n" +; while (<FH>) { chomp; my (email,name) = split('=',$_); if ($email eq $inputted_email) { $found = 1; break; ## exit loop; } } close FH; if (!$found) { ## Append to file open(FH, "<<", "$filename") || die "Cannot open $filename to append: + $!\n"; print FH, "$inputted_email=$inputted_name\n"; close FH; }

Replies are listed 'Best First'.
Re^2: Check For Dupes In FLat DB Before Adding
by chas (Priest) on Dec 15, 2005 at 00:49 UTC
    Do you mean "last" rather than "break"? Also, I don't think "<<" is a valid open mode.
    (Update/comment: If the record is found, why not "exit" rather than just break out of the loop? And otherwise just fall through to the append sub.)
      Do you mean "last" rather than "break"? Also, I don't think "<<" is a valid open mode.
      You are right. Too much C recently. As to the open mode, it should read...
      ## Append to file open(FH, ">>", "$filename") || die "Cannot open $filename to append: $ +!\n";
      If the record is found, why not "exit" rather than just break out of the loop?
      Because I don't know what needs to be done next.
        Because I don't know what needs to be done next.
        According to the OP, "if the email exists I would like to have it do nothing"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://516835]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.