how to delete an array from a db

They have: 1,587 posts

Joined: Mar 1999

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?

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

They have: 568 posts

Joined: Nov 1999

Use splice, it's the coolest array function

you could use

code:

splice(@array,1,2);
[/code]

i was chatting in #perl a few days ago and someone gave me a really cool snippet of code that removed any element of an array that contained certain text

code:
@array = do {my $f = 0; grep {$_ ne "monkey" | | $f ++} @array};
[/code]

That will remove any element that contains monkey. With a little work you could tweak it to work with regular expressions too, i'm sure it wouldn't be too hard. 

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.

They have: 568 posts

Joined: Nov 1999

Thanks for catching my error rob. That was a really odd error for me.

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?

They have: 1,587 posts

Joined: Mar 1999

anybody?

------------------
Earn $1 + CPM NOW from bottom of the page banners! CLICK 4 CASH

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.

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?

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.

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?

They have: 568 posts

Joined: Nov 1999

this is over my head...
sorry

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.

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.