Reputation: 46919
In the following perl code how to concatenate pwd with a string. In the following the output is in two different lines
$pwd=`pwd`;
my $string = $pwd . "/.somename";
print "$string";
Upvotes: 1
Views: 407
Reputation: 7593
Use chomp()
, like this:
my $pwd = `pwd`;
chomp($pwd);
my $string = $pwd . "/.somename";
print "$string";
http://perldoc.perl.org/functions/chomp.html
Upvotes: 1
Reputation: 76898
You just did. It just so happens there's a newline character in the middle.
$pwd=`pwd`;
chomp($pwd);
my $string = $pwd . "/.somename";
print "$string";
That being said ... don't do that. You should use cwd()
use Cwd;
my $string = cwd() . "/.somename";
print "$string\n";
Upvotes: 7
Reputation: 3184
$pwd=`pwd`;
chomp $pwd;
my $string = $pwd . "/.somename";
print $string;
Upvotes: 2