Hey guys, I have the following problem. I have created the following code where I add to the database all the usernames and passwords automatically that are in the text file.

#!/usr/bin/perl -w use DBI; # connect to the database my $dbh = DBI->connect('dbi:mysql:ass2db', 'test', '123') or die "Can't connect: ", $DBI::errstr; # prepare a SQL statement to insert your data # (using placeholders ("?") so you only have to # compile the statement once) my $sth = $dbh->prepare(<<SQL) or die "Can't prepare: ", $dbh->errstr; insert into ASS2 (User_name, Pass) values (?, ?) SQL # open up your data file open FILE, "data.txt" or die "Can't open: $!"; while (<FILE>) { chomp; # parse your data out of the file my($d1, $d2) = split(':', $_); # assuming tab-separated data #use system command to add user and set passwd system "useradd -m -p $d1 $d2"; # insert your data into the database $sth->execute($d1, $d2); } close FILE; $sth->finish; $dbh->disconnect;

This code works like a charm, now the problem is that I need to do the same process but removing the usernames and passwords using the text file.

the data.txt contains: user1:password1 user2:password2

I have tried everything and I cannot make it work. Im a total newbie with perl and I suck at programming so it makes it really hard for me. Any ideas would be much appreciated. Thanks


In reply to Delete users, account login from a txt file to the database by rodrigoo

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.