I think you have to re - read the File::Copy module documentation again. However, before you do that the following adjustment could make your code work perfectly
use File::Copy; my ($filetobecopied,$newfile); system('ls -lrt | tail -15 | grep working > temp.txt'); open FH,"<temp.txt" or die "can't open: $!"; open FH1,">final.txt" or die "can't open: $!"; while(<FH>) { my $line = $_; if($line=~/.*(L_.*)(\d{1})(\.txt)(\.working)/) { # print "$1 - $2 - $3 - $4 \n"; my $one = $1; my $two = $2; my $three = $3; my $four = $4; my $val = 1; print FH1 $one , '1' , $three,"\n============================== +============ \n"; } } $filetobecopied = "final.txt"; close FH1 or die "can't close:$!"; close FH or die "can't close: $!"; $newfile = "/u/mindspring/data/fulfillment/FSI/outgoing/"; copy($filetobecopied,$newfile) or die "File cannot be copied.";
This should work fine. The Principle is simple, open two file handlers, FH for input and FH1 for output, using the while loop, go over each line get and analysis lines that meet your condition in the "if condition". Print to the file handler FH1, which output to a file named "final.txt". Assign final.txt to a variable name, $filetobecopied, which is evetually copied to $newfile!
Now you can go over File::Copy module Documentation Again.
Hope this helps.In reply to Re: How to copy a file in a perl variable to a directory
by 2teez
in thread How to copy a file in a perl variable to a directory
by pavanpvss
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |