Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old August 3rd, 2000, 10:28 AM
rrandels rrandels is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: pa, usa
Posts: 8 rrandels User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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") | | die "Error opening databasen";
foreach $line(@all_records){
print LINKLIST $line;
}
close (LINKLIST);
print "Link has been removedn";
}[CODE]

anybody got any ideas?

------------------
rrandels.

Reply With Quote
  #2  
Old August 3rd, 2000, 03:13 PM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 9
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan

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..."

Reply With Quote
  #3  
Old August 3rd, 2000, 04:59 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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";
}
}

#############################################

Reply With Quote
  #4  
Old August 4th, 2000, 07:40 AM
rrandels rrandels is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: pa, usa
Posts: 8 rrandels User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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.

Reply With Quote
  #5  
Old August 4th, 2000, 10:13 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 9
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan
rrandels,
You can use a pipe deliminator("|")..




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

"The fear of the LORD is the beginning of knowledge..."

Reply With Quote
  #6  
Old August 4th, 2000, 06:11 PM
rrandels rrandels is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: pa, usa
Posts: 8 rrandels User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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.

Reply With Quote
  #7  
Old August 4th, 2000, 09:20 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > deleting a link... again


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway