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: Re: [ianilkumar] copy a file with a different name.: Edit Log



FishMonger
Veteran / Moderator

Sep 11, 2012, 6:44 AM


Views: 957
Re: [ianilkumar] copy a file with a different name.

1) Instead of shelling out to the date command, it would be better to use the strftime function from the POSIX module.

2) $PIN_HOME was never assigned a value.

3) You should always use the strict and warnings pragmas. They would have told to about the problem with $PIN_HOME.

4) You should verify that the copy completed successfully and output a proper error message if it didn't.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use POSIX qw(strftime);
use File::Copy;

my $ext = strftime("Y%m%d%H%M%S", localtime);
my $pin_home = '/home/user';
my $src_file = "$pin_home/sys/data/pricing/example/pin_usage_map";
my $new_file = "$pin_home/sys/data/pricing/example/pin_usage_map.$ext";

copy($src_file, $new_file) or die ("failed to copy '$src_file' to '$new_file' <$!>");



(This post was edited by FishMonger on Sep 11, 2012, 6:45 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Sep 11, 2012, 6:44 AM
Post edited by FishMonger (Veteran) on Sep 11, 2012, 6:45 AM


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

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