crate a file with same name in new location
Hi All,
I've got a program which reads a file and replaces some text with new text. After this how can i create a file with same name but in new location? The $var4 contains my original file name. Code:
open (MYFILE, 'filelist.txt'); |
Hi nanda22,
You just need to add something like: # Before the while loop open(OUTHNDL, ">/path/to/new/$var4") || die "Could not create file.\n"; # Inside the loop print OUTHNDL "$line\n"; # After the loop close(OUTHNDL); cheers, kbp P.S. .. or the really ugly hack: # Inside the loop system("echo $line >> /my/new/file"); |
Hi KBP,
Thaks a lot for your reply. it worked nicely. I just modified it little bit, placed open(OUTHNDL, ">/path/to/new/$var4") || die "Could not create file.\n"; inside the loop, because when i placed it outside, it was creating file name as "0", as $var4 value is been assigned to 0 at first. so when i placed it inside, it took value which i captured from another file. it is working fine. Thank you very much for your kind reply. |
Actually, the approved Perl method is
http://search.cpan.org/~dapm/perl-5....b/File/Copy.pm |
All times are GMT -5. The time now is 09:31 AM. |