Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need basic help with updating a file

dkenney1dkenney1 Posts: 4Member
I am writing a script for my two little boys to play a game. We
are not going to hack ourself so I am not doing strict etc. I mention
this because previous attempts to get help did not get the question
answered elsewhere,but referred to do strict and warnings. There is a ton more code than what I am going to show you...a re-write to strict would take a long time...not merited for a script for only use on a home system.

Scratch.dat is a dat file with 18 lines...
the_line|country_number

country.dat is also a dat file with 336 lines...
ln|nm|nr|ne|ea|se|so|sw|we|nw|mn|tt

I want to read all 18 lines of scratch.dat and update country.dat
so that if scratch.dat (country_number) is equal to country.dat (ln),
then country.dat (mn) would be changed to the value of scratch.dat
(the_line)...I need help with printing the updated country.dat file
back.

Please help me with this.

[code]# Have 18 rand numbers, now assign creatures to countrys
open (SCR, "scratch.dat") || &CgiDie ("SCRATCH could not be opened while attempting read");
@scra =;
close (SCR);
$reps = 1;
while ($reps < 19)
{
foreach $mine (@scra)
{
chomp($mine);
($the_line, $country_number) = split (/|/, $mine);
open (CNT, "+>country.dat") || &CgiDie ("Country list could not be opened trying to position creatures");
@ymca =;
foreach $thine (@ymca)
{
chomp($thine);
($ln, $nm, $nr, $ne, $ea, $se, $so, $sw, $we, $nw, $mn, $tt ) = split (/|/, $thine);
if ($ln == $country_number)
{
$mn = $the_line;
}
} # End of for each on country file
$reps++;
} # End of for each @scra - scratch
print CNT;
close (CNT);
} # End of while
#unlink ("scratch.dat");
&printout;
}
else
{
&signin;
}[/code]
Sign In or Register to comment.