Hi pavanpvss,

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.