Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: problem in a small script

by serf (Chaplain)
on Jan 16, 2006 at 00:26 UTC ( #523371=note: print w/ replies, xml ) Need Help??


in reply to Re: problem in a small script
in thread problem in a small script

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'});


Comment on Re^2: problem in a small script
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://523371]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2014-10-02 05:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (49 votes), past polls