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

    Join Date
    Jul 2000
    Location
    pa, usa
    Posts
    8
    Rep Power
    0
    I've gotten previous help with this subject... and now, i've run into this problem.

    I've adopted this code... and it still is giving me problems.

    whenever i have 3+ links, and i tell my program to delete the selected link, it deletes all of the links EXCEPT the one that i told it to delete. when i have 1 link in my db ,i won't delete it, but with 2 links, the db works fine.


    my code:
    [CODE]sub deletelink {
    open (LINKLIST, "linklist.dat") | | die "Error opening databasen";
    @datas = <LINKLIST>;
    close (LINKLIST);
    foreach $data (@datas) {
    ($linkinfo1,$linkinfo2) = split("/-", $data);
    $link=$linkinfo1."/-".$linkinfo2;
    @all_records=$data if($link ne "$form{'link'}");
    }
    open (LINKLIST, ">linklist.dat") &#0124; &#0124; die "Error opening databasen";
    foreach $line(@all_records){
    print LINKLIST $line;
    }
    close (LINKLIST);
    print "Link has been removedn";
    }[CODE]

    anybody got any ideas?

    ------------------
    rrandels.
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    whenever i have 3+ links, and i tell my program to delete the selected link, it deletes all of the links EXCEPT the one that i told it to delete.


    Ryan,

    what is this 3+ links . can you show me how you are displaying this 3+ links in your html form?


    <<
    foreach $data (@datas) {
    ($linkinfo1,$linkinfo2) = split("/-", $data);
    $link=$linkinfo1."/-".$linkinfo2;
    @all_records=$data if($link ne "$form{'link'}");
    }
    >>


    ($linkinfo1,$linkinfo2) = split("/-", $data);
    $link=$linkinfo1."/-".$linkinfo2;

    this two lines you can avoid in your code..

    it can be just..


    foreach $data (@datas) {
    @all_records=$data if($data ne "$form{'link'}");
    }

    the above case $form{'link'} value should be something like "link1/-link2".other wise it won't match properly.

    ---------



    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    For whatever reason, you should never use "/-" as the field delimiter, especially you are working on links in your case.

    Try to set $linkinfo1 as "link description" and $linkinfo2 as "url"

    #############################################
    sub deletelink {
    open (LINKLIST, "linklist.dat") &#0124; &#0124; die "Error opening databasen";
    @datas = <LINKLIST>;
    close (LINKLIST);
    $count = 0;
    foreach $data (@datas) {
    chomp $data;
    ($linkinfo1,$linkinfo2) = split(/|/, $data);
    if ($linkinfo2 eq "$form{'link'}") {
    $link = $1;
    last;
    $link_found = 1;
    }
    else {
    $count++;
    $link_found = 0;
    }
    }
    splice (@datas, $count, 1);
    open (LINKLIST, ">linklist.dat") &#0124; &#0124; die "Error opening databasen";
    foreach $line (@datas){
    print LINKLIST $line;
    }
    close (LINKLIST);
    if ($link_found == "1") {
    print "Link has been removedn";
    }
    else {
    print "Link not found. DB untouchedn";
    }
    }

    #############################################
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    pa, usa
    Posts
    8
    Rep Power
    0
    well then what WOULD be a good field delimiter for a link? and because i'm a self taught newbie, i don't understand the variable verses the "variable". what's the difference?

    and my link file is set up like this:
    Altavista/-http://www.altavista.com
    Yahoo's web site!/-http://www.yahoo.com
    AOL's crappy site/-http://www.aol.com

    that's all it is... i'll try out freebsd's code and see if it works. thanks alot guys

    ------------------
    rrandels.
  8. #5
  9. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    rrandels,
    You can use a pipe deliminator("|")..




    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    pa, usa
    Posts
    8
    Rep Power
    0
    damnit... now, using freebsd's code to delete the link, if the link is "spazznet|http://spazznt.hypermart.net", when i use the | to split it, i get "s" as the first part of the split, and "p" as the second. if you didn't notice, it's the first two words of spazznet, so what's goin wrong here?



    ------------------
    rrandels.
  12. #7
  13. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>when i use the | to split it, i get "s" as the first part of the split

    Make sure this line exactly matches yours.
    ($linkinfo1,$linkinfo2) = split(/|/, $data);

    Not this one..
    ($linkinfo1,$linkinfo2) = split("|", $data);

    >>damnit... now

    Please don't ever use such language here.

IMN logo majestic logo threadwatch logo seochat tools logo