I have a very short tutorial Perl script:
#!/usr/bin/perl
print "The date is ",`date`;
print "The date is `date`",".\n";
$directory=`pwd`;
print "\nThe current directory is $directory.";
and the output:
The date is Sat Jul 2 17:04:58 PDT 2011
The date is `date`.
The current directory is total 20
-rwxr-xr-x 1 yan yan 433 2011-07-02 15:58 36
-rwxr-xr-x 1 yan yan 313 2011-07-02 16:29 43
-rwxr-xr-x 1 yan yan 116 2011-07-02 16:51 45
-rwxr-xr-x 1 yan yan 149 2011-07-02 16:53 46
-rwxr-xr-x 1 yan yan 145 2011-07-02 17:02 47
But, if I just run pwd, I got:
yan@ubuntu:~/bin/blackperl$ pwd
/home/yan/bin/blackperl
Is there any logical explanation to the mystery here?
I can't exlpain the mystery either, but you could try to use the Perl Core module Cwd instead of the pwd command:
use warnings;
use strict;
use Cwd;
my $dir = getcwd();
print "$dir\n";
One advantage is that Cwd is more portable than pwd.
See also: UNIX 'command' equivalents in Perl
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With