#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    pa, usa
    Posts
    8
    Rep Power
    0
    If i have an array that is multiline like:

    ryan c:randels
    joe b:frank
    travis f:collins

    and i want to delete one of those lines, how would i go about it if i don't know the absolute location, all i know is the text.

    sorry, i'm self taught.



    ------------------
    rrandels.
  2. #2
  3. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    Use "splice".
    Here is an example:

    open(DB,"db.txt");
    @lines = <DB>;
    close(DB);
    $count = 0;
    foreach $line (@lines) {
    chomp $line;
    ($fullname,$username)=split(/:/,$line);
    if ($username eq "$FORM{'username')") {
    $username = $1;
    last;
    }
    else {
    $count++;
    }
    }
    splice(@lines, $count, 1);
    #the following will remove the matched username from db.txt and refresh all lines
    open(DB, ">db.txt");
    foreach $line (@lines) {
    print DB $line;
    }
    #the following will update a new record
    open(DB, ">>db.txt");
    print DB "$FORM{'fullname'}:$FORM{'username'}n";
    close(DB);
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    pa, usa
    Posts
    8
    Rep Power
    0
    that doesn't work =(

    ugh, this is a pain in the ***!



    ------------------
    rrandels.
  6. #4
  7. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>that doesn't work =(

    This answer doesn't tell me anything either.
    Well, just read my code and found one syntax error at -> if ($username eq "$FORM{'username')") {
    which should be:
    if ($username eq "$FORM{'username'}") {

    You need to give more details and be more specific. Simply saying: "Oh no, I've got 500 internal error" tells me nothing.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    15
    I'll assume this is to get ride of an entry in a password file. Try this:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    open(DB, "$pass_file") &#0124; &#0124; print "Error: $!";
    @db = <DB>;
    close(DB);

    foreach $line (@db) {
    ($user,$pass) = split(/:/, $line);
    if ($FORM{del_name} eq $user) {} else {
    $ins_data = $user . ":" . $pass;
    push(@insert, $ins_data)
    }#End else
    }#End forech

    open(DB, ">$pass_file") &#0124; &#0124; print "Error: $!";
    flock(DB, 2);
    foreach $line (@insert) {
    print DB $line;
    }#end foreach
    flock(DB, 8);
    close(DB);
    print "Deleted: $FORM{del_name}";
    [/code]
    del_name is a form item that is used to get the delete info from.

    Note: This is "ledjon". The forumd downtime must have really messed with stuff. I used to "Forget your password?" link and it e-mailed me with nothing as my user name and password "

IMN logo majestic logo threadwatch logo seochat tools logo