how to delete an array from a db
i've got a db in the following similar format:
1|name|date|city|birthplace
2|name|date|city|birthplace
3|name|date|city|birthplace
how would i delete all of array #2 from the db using a script?
thanks in advance
------------------
Thumbs up or downs ratings and more on affiliate programs.CLICK 4 CASH
Traffic-Website.com free traffic, affiliate programs, hosting, & domain names.
My Site got hacked, but i'm coming back?
japhy posted this at 05:05 — 17th February 2000.
They have: 161 posts
Joined: Dec 1999
The Perl FAQ talks about how to efficiently remove lines from a file. From perlfaq5, "How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file?"
You can do this nicely using Perl's inplace editing, which is explained in the FAQ. I'm also in the process of writing a tutorial on using it.
------------------
--
MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve
Orpheus posted this at 05:30 — 17th February 2000.
They have: 568 posts
Joined: Nov 1999
Use splice, it's the coolest array function
you could use
Rob Pengelly posted this at 13:45 — 17th February 2000.
They have: 850 posts
Joined: Jul 1999
I will try and add on to Orpheus's splice explanation with an example.
say we have
@arr=("a","b","c","d");
Now, we want to delete "c" in the @arr because it is a crappy letter.
splice @arr,2,1;
This means
splice the @arr, starting at the second element (remember "a" would be 0, so "c" would be 2) and deleting one element.
If we wanted to delete both of element "c" and "d" we could use:
splice @arr,2,2;
How would this help you?
You could open the file and put each line into an @array.
open(IN,"<file.txt");
@array = <IN>;
close(IN);
than you could set up two variables to what you want deleted:
$start = 1;
$num_of_elements_deleted = 1;
than splice:
splice @arr, $start,$num_of_elements_deleted;
And than you would want to print the @array back into the file:
open(IN,">file.txt");
print @array;
close(IN);
Of course this could probably take longer than just doing in manually. Hope that helps.
------------------
Windmills always turn counter-clockwise. Except for the windmills in Ireland.
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
Orpheus posted this at 14:18 — 17th February 2000.
They have: 568 posts
Joined: Nov 1999
Thanks for catching my error rob. That was a really odd error for me.
fairhousing posted this at 10:21 — 20th February 2000.
They have: 1,587 posts
Joined: Mar 1999
hmm, i can't get this to work. maybe i asked my question wrong.
i'd like to be able to delete the 2nd line of my example completely using perl/cgi.
------------------
Thumbs up or downs ratings and more on affiliate programs.CLICK 4 CASH
Traffic-Website.com free traffic, affiliate programs, hosting, & domain names.
My Site got hacked, but i'm coming back?
fairhousing posted this at 05:28 — 27th February 2000.
They have: 1,587 posts
Joined: Mar 1999
anybody?
------------------
Earn $1 + CPM NOW from bottom of the page banners! CLICK 4 CASH
Rob Pengelly posted this at 15:27 — 27th February 2000.
They have: 850 posts
Joined: Jul 1999
I just used the script I made above, but added a little.
Check out http://dlo.net/~rob/cgi-bin/delline.cgi
The textfile is at http://dlo.net/~rob/cgi-bin/dellinedata.txt
and the source is at http://dlo.net/~rob/cgi-bin/delline.txt
It isn't perfect, but I think it is what you need.
Hope that helps.
------------------
Windmills always turn counter-clockwise. Except for the windmills in Ireland.
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
fairhousing posted this at 23:58 — 27th February 2000.
They have: 1,587 posts
Joined: Mar 1999
thx robp!
u get my vote for a moderator position
for some reason it want let me delete #2
------------------
Earn $1 + CPM NOW from bottom of the page banners! CLICK 4 CASH
Traffic-Website.com free traffic, affiliate programs, hosting, & domain names.
My Site got hacked, but i'm coming back?
Rob Pengelly posted this at 00:40 — 28th February 2000.
They have: 850 posts
Joined: Jul 1999
Hmmm, will it let you delete any of the lines using my code?
------------------
Recycling one glass jar, saves enough energy to watch T.V for 3 hours.
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
fairhousing posted this at 22:36 — 28th February 2000.
They have: 1,587 posts
Joined: Mar 1999
yeah, i deleted bunches, it just didn't let me delete #2 on ur text file.
------------------
Earn $1 + CPM NOW from bottom of the page banners! CLICK 4 CASH
Traffic-Website.com free traffic, affiliate programs, hosting, & domain names.
My Site got hacked, but i'm coming back?
Orpheus posted this at 23:16 — 28th February 2000.
They have: 568 posts
Joined: Nov 1999
this is over my head...
sorry
Rob Pengelly posted this at 23:51 — 28th February 2000.
They have: 850 posts
Joined: Jul 1999
No idea?
I did do a few changes to the code for fun if you wanna check it out.
------------------
Recycling one glass jar, saves enough energy to watch T.V for 3 hours.
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
fairhousing posted this at 14:34 — 3rd March 2000.
They have: 1,587 posts
Joined: Mar 1999
awesome, i manipulated the code to fit my needs and it works! thx for all the help folks, ecspecially robp.
------------------
Earn $1 + CPM NOW from bottom of the page banners! CLICK 4 CASH
Traffic-Website.com free traffic, affiliate programs, hosting, & domain names.
My Site got hacked, but i'm coming back?
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.