473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

script is printing output correct but not the actual output

154 100+
script is printing output correct but not the actual output.

Basically what the script is doing it taking a 1 flat file

then it is splits the file into smaller files in 1000 record increments

then it creates another file and adds the header the file contents of the old file.

and the file with the header is then renamed to file format i want which is txt.

Now the problem is that the file never renames but when i print it it shows the new file name as the txt file i wanted. but it never changes the physical file.

Hope you guys could please help me the rest of the script works fine . the file splits file and the header and contents are fine. deleting the old files and renaming to txt is where i am having the problem.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. $| = 1;
  3.  
  4. use File::Copy;
  5.  
  6. ######################### Splitting Files ################################
  7. my $read = "Files read from dir";
  8. my $split = "Files split in 1000 records each";
  9. my $del = "Source file deleted";
  10. my $move = "Source files moved to /home/tibco/tibco/Susan/split_finish";
  11.  
  12. open(LOG, ">>/home/baddabing/Susan/splitlog.log") || die (" error recording log: $!");
  13. my $time_now = localtime;
  14.  
  15. my $srcdir = "/home/baddabing/Susan/dropoff";
  16. my $dest = "/home/baddabing/Susan/split_finish";
  17.  
  18. for (;;) {
  19.     opendir(DIR, $srcdir) or die "Can't open $srcdir: $!";
  20.     @files = grep {!/^\.+$/} readdir(DIR);
  21.     close(DIR);
  22.  
  23.     if (!@files) {
  24.         print "No files in dir.\n\n";
  25.         last;
  26.     }
  27.  
  28.     print "Time: $time_now ----- $_[0]", "\n";
  29.     print LOG "Time: $time_now ----- $_[0]", "\n";
  30.  
  31.     ##### Reading Header from File #####
  32.     $file = "@files";
  33.     print "Source File is $file \n\n";
  34.  
  35.     open(INFILE, "< $srcdir/$file") or die (" Could not open File $!");
  36.     $line1 = <INFILE>;
  37.     close (INFILE);
  38.     print " This is the header: $line1 \n";
  39.  
  40.     #UNIX Split Command Running
  41.     system "split -l 500 $srcdir/int_sap* $srcdir/int_sap*";
  42.     print "Time: $time_now ----- $_[1]", "\n";
  43.     print LOG "Time: $time_now ----- $_[1]", "\n";
  44.     sleep 2;
  45.  
  46.     system "rm /home/tibco/tibco/Susan/dropoff/*.txt";
  47.     print "Time: $time_now ----- $_[2]", "\n";
  48.     print LOG "Time: $time_now ----- $_[2]", "\n";
  49.     sleep 1;
  50.  
  51.     system "mv /home/baddabing/Susan/dropoff/* /home/baddabing/Susan/split_finish";
  52.     print "Source files were moved to /home/baddabing/Susan/split_finish\n\n";
  53.     print LOG "Time: $time_now ----- $_[3]", "\n";
  54.     sleep 1;
  55.  
  56. ######################### Rename Files ####################################
  57.  
  58.     my $path2 = "/home/tibco/tibco/Susan/split_finish";
  59.     opendir(DIR, $path2) || die "can't opendir $path: $!";
  60.     @files2 = grep {!/^\.+$/} readdir(DIR);
  61.     close(DIR);
  62.  
  63.     $i = 1;
  64.     foreach (@files2) {
  65.         @_ = split(/\./,$_);
  66.  
  67.         my $name = "$_";
  68.  
  69.         my $name3 = "$_[0]";
  70.         chomp($name);
  71.         print "This is the name $name \n\n";
  72.  
  73.         open(INFILE2,"< $dest/$name") || die(" Could not open INFILE2 File!");
  74.         $header = <INFILE2>;
  75.         chomp($header);
  76.         print "This is the infile header: $header \n ";
  77.  
  78.         my $name2 = "$name$i";
  79.  
  80.         print "************* $name2 ********** \n\n\n";
  81.  
  82.         if($header eq "$line1") {}
  83.         else {
  84.             open(OUTFILE2, "> $dest/$name2") || die ("Could not OUTFILE2 open file $!");
  85.             print OUTFILE2 "$line1";
  86.             print OUTFILE2 "$header";
  87.             while (<INFILE2>) {
  88.                 print OUTFILE2 "$_";
  89.             }
  90.             close OUTFILE2;
  91.         }
  92.  
  93.         close INFILE2;
  94.         unlink($name);
  95.         print "File $name Removed \n\n";
  96.  
  97.         my $new_name = $name3.$i.'.txt';
  98.  
  99.         system "rn $dest/$name2 $new_name";
  100.         print "$new_name renaming is completed \n\n";
  101.         sleep 2;
  102.  
  103.         $i++;
  104.         close LOG;
  105.     }
  106.     print "\n\n ---------------- All files processed ------------------\n\n";
  107. }
Feb 21 '07 #1
3 1626
@jonathan184

Try calling
Expand|Select|Wrap|Line Numbers
  1. rename("$dest/$name2", $new_name) or print "$!\n";
instead of
Expand|Select|Wrap|Line Numbers
  1. system "rn $dest/$name2 $new_name";
Greetz, Doc
Feb 22 '07 #2
jonathan184
154 100+
Thanks that worked but if i wanted to put it in the same dir as the source.
the renaming part i mean i want it to rename in the same dir and output there.

Right now the rename works and it outputting to the folder level up.
Feb 22 '07 #3
jonathan184
154 100+
Nevermind I got it but thanks for all your help I guess i overlooked the simple stuff :)

@jonathan184

Try calling
Expand|Select|Wrap|Line Numbers
  1. rename("$dest/$name2", $new_name) or print "$!\n";
instead of
Expand|Select|Wrap|Line Numbers
  1. system "rn $dest/$name2 $new_name";
Greetz, Doc
Feb 22 '07 #4

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

Similar topics

3
by: Robert | last post by:
Hello, I am trying to get output formatted from a non-php script that I post to. Example: <form method=POST action=www.myurl.com/ColdFusion.cfm> bla bla bla </form>
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
8
by: Tinus | last post by:
Hello all, Because you have been so helpfull the last couple of times, I thought after testing and wasting more than 20 pages (and google-ling for 3 days :-( ). I would ask you again for your...
7
by: DazedAndConfused | last post by:
I have a 8.5 x 11 landscape document with about 1/4 inch of space on the left and right where there is no print. The document displays perfect in print preview, but when I print it, about 1/2 inch...
6
by: sathyashrayan | last post by:
Dear group, Following is a exercise from a book called "Oreilly's practical C programming". I just wanted to do a couple of C programming exercise. I do have K and R book, but let me try some...
0
by: Vincent | last post by:
Dear all, I have implemented a class to export the content of RichTextBox to image in WYSISYG mode so that line breaks on the screen are the same as exported. C# Code: public struct...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
8
by: Frank Rizzo | last post by:
I am trying to print huge images (much bigger than target paper). I try and use e.PageSettings.HardMarginX and e.PageSettings.HardMarginY in the PrintDocument's PrintPage event to try and...
1
by: mehdi | last post by:
Hi, Consider a printing scenario where I have to draw the entire page on a 827x1169 (.01 inch) size. Thereafter, the entire bitmap has to be resized to fill a given Bounds rectangle (keeping the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.