|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
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") | | 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
|
||||
|
||||
|
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..." |
|
#3
|
|||
|
|||
|
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") | | 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") | | 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"; } } ############################################# |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
||||
|
||||
|
rrandels,
You can use a pipe deliminator("|").. ------------------ SR - webshiju.com "The fear of the LORD is the beginning of knowledge..." |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
|||
|
|||
|
>>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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > deleting a link... again |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|