logic problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ramesh54
    New Member
    • Jul 2008
    • 37

    logic problem

    Hello friends,

    I have a directory Z with file name Z.txt.
    I would like to copy this file Z.txt to 8 new dir with new filenames as follows
    dir 1 1.txt
    dir 2 2.txt
    dir 3 3.txt
    dir 4 4.txt
    dir 5 5.txt
    dir 6 6.txt
    dir 7 7.txt
    dir 8 8.txt

    I would like to then open 1.txt from dir 1 and edit the first 4 lines and it
    would be better if the program can ask me what to enter in these lines. I need
    to do the same for all the directories

    Looking forward to your response.

    Regards,
    Ramesh
  • nithinpes
    Recognized Expert Contributor
    • Dec 2007
    • 410

    #2
    Please do not post your homework questions here. Let us know what you have tried so far and where you are facing problem, so that someone here can help you.

    Comment

    • ramesh54
      New Member
      • Jul 2008
      • 37

      #3
      Hi all,

      I have tried the following, I know the logic behind it, but i am unable to put it rightly using the Perl format. I have tried the following

      #!/usr/bin/perl
      open FILE, "z.txt" or die $!;
      while (<FILE>) {
      print $_;
      }
      mkdir("1", 0777) || print $!;
      mkdir("2", 0777) || print $!;
      mkdir("3", 0777) || print $!;
      mkdir("4", 0777) || print $!;
      mkdir("5", 0777) || print $!;
      mkdir("6", 0777) || print $!;
      mkdir("7", 0777) || print $!;
      mkdir("8", 0777) || print $!;
      print " -Done";

      exit;

      I am have all the new directories with respective names. I want to copy the file z.txt from dir z to the new dir 1 with file name 1.txt , dir 2 with file name 2.txt and so on...
      How could I use the copy function here.
      Looking forward to your response.

      Regards,
      Ramesh

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        perl has no copy function. You would use the File::Copy module or simply use the open() function to open and read the file and then use "print" to write it to the new directories.

        This is not a logic problem. This is an excersize in learning basic file IO operations or possibly more specifically how to mkdir and copy files. Any perl book/tutorial that covers "File Access" or "File IO" should provide you more than enough information to accomplish this very simple task.

        Comment

        Working...