http://www.perlmonks.org?node_id=1071342


in reply to Noob question

Previous answers (sensibly) recommending Cwd notwithstanding, your problem in the top example is that your output is running into your shell prompt for the following command (whatever that might be). Your chomp is removing the trailling newline that you might need to do this. You could therefore chomp after the print if that's the way you want to go about it.

However, your second script works fine if we adjust the shebang:

$ cat cwdt.pl #!/usr/bin/perl use strict; use warnings; my $currDir = `pwd`; chomp $currDir; print "$currDir\n"; $ ./cwdt.pl /tmp $

This suggests that the code you've posted may not be the code you are running.