Perl

Moderators: Jonathan
Number of threads: 1211
Number of posts: 3568

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need basic help with updating a file Posted by dkenney1 on 8 Mar 2010 at 12:29 PM
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.

# Have 18 rand numbers, now assign creatures to countrys
open (SCR, "scratch.dat") || &CgiDie ("SCRATCH could not be opened while attempting read");
        @scra =<SCR>;
        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 =<CNT>;
            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;
        }




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.