in reply to problem in a small script

Think you mean to use backticks in several places...

my $next_backup_file = "daily-incremental-backup." . 'date +%Y%m%d'; should be ... my $next_backup_file = "daily-incremental-backup." . `date +%Y%m%d`;

and

my $youngest = "svnlook youngest $svn_repos"; should be.... my $youngest = `svnlook youngest $svn_repos`;

Not sure what you are trying to accomplish with this line of code, but it probably is mean to be backticked also.

print 'gzip -9 $backups_dir/$next_backup_file'; should be print `gzip -9 $backups_dir/$next_backup_file`;

Several other places that are commented also look like they are meant to be backticked.

Scott

Replies are listed 'Best First'.
Re^2: problem in a small script
by serf (Chaplain) on Jan 16, 2006 at 00:26 UTC
    I'd normally not use backticks myself to run something external to get data that Perl can easily give me, but if you do you may need to chomp the results. If you try the following you will see that the un-chomp()ed newline returned at the end of the date command pushes the second "*" down:
    #!/usr/bin/perl use strict; use warnings; my $next_backup_file = "daily-incremental-backup." . `date +%Y%m%d`; print "*$next_backup_file*\n";
    You could use Perl's build in time command and then wouldn't have to chomp the result. There are lots of ways to use this, this is one way I have done it:
    # # Get time for now. # my %NOW; ($NOW{'sec'}, $NOW{'min'}, $NOW{'hour'}, $NOW{'mday'}, $NOW{'mon'}, $NOW{'year'}, $NOW{'wday'}, $NOW{'yday'}, $NOW{'isdst'}) = localtime time; my $next_backup_file = sprintf("daily-incremental-backup.%04i%02i%2i", $NOW{'year'} + 1900, $NOW{'mon'} + 1, $NOW{'mday'});