Reputation: 87
#!/usr/bin/perl -w
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);
use strict;
print "Content-type: text/plain\n";
print "\n";
my $date = system('date');
print "Date :: $date";
The above code keeps producing the output of Date :: 0
instead of the current date.
I can't find any solution for this problem. Please help.
Upvotes: 1
Views: 45
Reputation: 4709
Instead of using system
command, use backtick
. system
command doesn't return value in a variable. Change this line:
my $date = system('date');
to
my $date = `date`;
See this for more understanding about system
and backtick
:
https://stackoverflow.com/a/800105/4248931
Upvotes: 2
Reputation: 6998
The return value of the system command is the return value of the call. For a successful call this will be 0. If you want to capture the output of a command use backticks or IPC. Look at this answer: Capture the output of Perl system()
my $date = `date`;
print "Date :: $date";
But better would be to use DateTime.
Upvotes: 1