467,202 Members | 1,083 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,202 developers. It's quick & easy.

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
Jul 7 '08 #1
  • viewed: 998
Share:
3 Replies
nithinpes
Expert 256MB
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.
Jul 7 '08 #2
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
Jul 7 '08 #3
KevinADC
Expert 2GB
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.
Jul 7 '08 #4

Post your reply

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

Similar topics

reply views Thread by radha | last post: by
60 posts views Thread by Fotios | last post: by
reply views Thread by davidpendry@europe.com | last post: by
24 posts views Thread by cassetti@gmail.com | last post: by
15 posts views Thread by Jay | last post: by
9 posts views Thread by SAL | last post: by
15 posts views Thread by bruno.desthuilliers@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.