CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
How to export a whole txt file into a specified folder

 



snowpl10
New User

Jun 9, 2017, 12:11 PM

Post #1 of 6 (2024 views)
How to export a whole txt file into a specified folder Can't Post

I have a question about reading and exporting a whole txt file to a specific folder. For example, I use the code below, but in the new exported txt files, they all have just one line: GLOB(0x7fb0c...).
How to copy the content from $simdata to $outfile and export? The reason that I wanted to do this is that I can export the different files to different places or renaming them, as they are over-written in the old directory. Thanks for your help.

open my $simdata, '<', '/theOldPath/file.txt' or die $!;
open my $outfile, ">", "/theNewPath/file.txt" or die $!;
print $outfile "$simdata\n";


Chris Charley
User

Jun 9, 2017, 1:04 PM

Post #2 of 6 (2019 views)
Re: [snowpl10] How to export a whole txt file into a specified folder [In reply to] Can't Post

Probably your best bet is File::Copy.


snowpl10
New User

Jun 9, 2017, 1:05 PM

Post #3 of 6 (2017 views)
Re: [Chris Charley] How to export a whole txt file into a specified folder [In reply to] Can't Post

Thanks, I will look at the function. Will this influence the original file?


Chris Charley
User

Jun 9, 2017, 1:08 PM

Post #4 of 6 (2015 views)
Re: [snowpl10] How to export a whole txt file into a specified folder [In reply to] Can't Post

move 'moves' the file to the destination. copy makes a copy of the file in the destination.


snowpl10
New User

Jun 9, 2017, 1:22 PM

Post #5 of 6 (2009 views)
Re: [Chris Charley] How to export a whole txt file into a specified folder [In reply to] Can't Post

Thanks, this function is pretty convenient. I put it here, so to verify it is correct?

use File::Copy;
copy("sourcefile","destinationfile") or die "Copy failed: $!";


Laurent_R
Veteran / Moderator

Jun 10, 2017, 12:35 AM

Post #6 of 6 (1991 views)
Re: [snowpl10] How to export a whole txt file into a specified folder [In reply to] Can't Post

Yes, that's correct, provided you replace the "sourcefile" and "destinationfile" strings with what you actually need, i.e. proper file names prefixed by the relevant (relative or absolute) paths.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives