How to make this print to file right --

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dkenney1
    New Member
    • Feb 2010
    • 2

    How to make this print to file right --

    Appreciate help with this, I want the file modified and correctly printed... appreciate your help.
    Code:
    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
    
                close (CNT);
            } # End of while
        #unlink ("scratch.dat");
        &printout;
        }
    else
        {
        &signin;
            }
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    You really need to please provide more information. You have fed us a script but have not described what you are seeing that is wrong. What is the input? What do you expect for output into the new file? You have to give us as much information as you can to help us help you.

    Regards,

    Jeff

    Comment

    • dkenney1
      New Member
      • Feb 2010
      • 2

      #3
      My apologies. scratch.dat has 18 lines and each line is:
      junk (line number) |country number. Country.dat is over 300 lines. For each loop, I want to read each line of scratch.dat and match the country number in country.dat which is $ln. When the right line of country.dat is found, I then want
      to change $mn of country dat to equal $the_line of the scratch file. When all 18
      changes are done, I need to write country.dat back with the changes made.
      As a side note, I am reading the forum replies and tips. I realize I am needing to change my script to use warnings and strict. Only reason I havent here is I am having to rewrite the whole script and getting this to write the file
      back is bugging me. This is only a fraction of that script. I have tried writing it back to country.dat and gotten crazy results. I am not attacking it right.

      Comment

      • chaarmann
        Recognized Expert Contributor
        • Nov 2007
        • 785

        #4
        We are not able to help you, unless you provide more information.
        We can't run the script to see what you mean with "crazy" results, because
        1.) we don't have the files scratch.dat and country.dat.
        2.) the script is incomplete.
        So why don't you provide samle data? (not all 300 lines, 3 carefully chosen ones are enough!)
        Show us the "crazy" results. And important, tell us what output you expected instead.

        Comment

        Working...