By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,373 Members | 1,984 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,373 IT Pros & Developers. It's quick & easy.

How to make this print to file right --

P: 2
Appreciate help with this, I want the file modified and correctly printed... appreciate your help.
Expand|Select|Wrap|Line Numbers
  1. open (SCR, "scratch.dat") || &CgiDie ("SCRATCH could not be opened while attempting read");
  2.         @scra =<SCR>;
  3.         close (SCR);
  4.         $reps = 1;
  5.         while ($reps < 19)
  6.         {
  7.         foreach $mine (@scra)
  8.             {
  9.             chomp($mine);
  10.             ($the_line, $country_number) = split (/\|/, $mine);
  11.             open (CNT, "+>country.dat") || &CgiDie ("Country list could not be opened trying to position creatures");
  12.             @ymca =<CNT>;
  13.             foreach $thine (@ymca)
  14.                 {
  15.                 chomp($thine);
  16.                 ($ln, $nm, $nr, $ne, $ea, $se, $so, $sw, $we, $nw, $mn, $tt ) = split (/\|/, $thine);
  17.                 if ($ln == $country_number)
  18.                     {
  19.                     $mn = $the_line;
  20.                     }
  21.                 } # End of for each on country file
  22.             $reps++;
  23.             } # End of for each @scra - scratch
  25.             close (CNT);
  26.         } # End of while
  27.     #unlink ("scratch.dat");
  28.     &printout;
  29.     }
  30. else
  31.     {
  32.     &signin;
  33.         }
Feb 10 '10 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 2.5K+
P: 3,503
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.


Feb 10 '10 #2

P: 2
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.
Feb 10 '10 #3

Expert 100+
P: 785
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.
Feb 12 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.