PDA

View Full Version : Search and Replace HELP!



jokaroo
April 19th, 2001, 07:47
I need some HELP! lol
Here is the code:

sub modify_data {
srand(time ^ $$);
$_ = rand(DATA);
if ($ENV{'REMOTE_ADDR'} eq $data[11]) {
print "Content-type: text/html\n\n";
print "$reprimand";
exit;
}
else {
if ($rating != "1") {
$value1 = $data[0];
}
else{
$value1 = $data[0] +1;
}
if ($rating != "2") {
$value2 = $data[1];
}
else{
$value2 = $data[1] +1;
}
if ($rating != "3") {
$value3 = $data[2];
}
else{
$value3 = $data[2] +1;
}
if ($rating != "4") {
$value4 = $data[3];
}
else{
$value4 = $data[3] +1;
}
if ($rating != "5") {
$value5 = $data[4];
}
else{
$value5 = $data[4] +1;
}
if ($rating != "6") {
$value6 = $data[5];
}
else{
$value6 = $data[5] +1;
}
if ($rating != "7") {
$value7 = $data[6];
}
else{
$value7 = $data[6] +1;
}
if ($rating != "8") {
$value8 = $data[7];
}
else{
$value8 = $data[7] +1;
}
if ($rating != "9") {
$value9 = $data[8];
}
else{
$value9 = $data[8] +1;
}
if ($rating != "10") {
$value10 = $data[9];
}
else{
$value10 = $data[9] + 1;
}
open(DATA,">$data_dir/data.txt") || die $!;
print DATA "$value1|$value2|$value3|$value4|$value5|$value6|$value7|$val ue8|$value9|$value10|$data[10]";
close (DATA);
}
}


Now let me explain, what I am trying to do is use the array DATA to read the file and pick one specific line. Preferrerably in random, or at least in line order. The file would look something like this...

9|1|2|2|0|0|1|0|3|36|http://www.url.com
9|1|2|2|0|0|1|0|3|36|http://www.url.com

Not only do I need it to read, but I also need to add data to each number column. I only need to read the url. What I need help is to get the above code or any possible way to search for a random line in the text file and read/print to it, making sure each and every other line is not touched except the randomly selected one. I just added the above code to help you out so you get a more vivid picture of the problem.