Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return hostname 1

Status
Not open for further replies.

blarneyme

MIS
Jun 22, 2009
160
US
Code:
use Sys::Hostname;
$host = hostname;
$conf = "$host_file.txt";
print "$conf\n";
returns .txt

changing the $conf line to:
Code:
$conf = '$host_file.txt";
returns $host_file.txt

How do I get $conf to return the actual hostname in $host so it prints realhostname_file.txt ?
 
Ah, looks like you got caught by the interpolation seeing "host_file" as a variable.

The first answer is to use curly braces to delimit the variable name thus:

Code:
$conf = "${host}_file.txt";

The second (to use your concatenation) is not to use interpolation at all but just to join the two parts thus:

Code:
$conf = $host . '_file.txt';

HTH :)


Trojan.
 
BTW:

While I think of it, if you'd used
Code:
use warnings;
use strict;
perl might have offered a clue or two.

Just a thought.




Trojan.
 
Thanks. I wasn't aware you could use ${variable} in Perl like you can in ksh.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top