U
usenet
Greetings.
I have two variable, $host and $user (and $user could be undef).
I wish to construct a string such as would be used in an FTP command,
such as:
(e-mail address removed)
However, if $user is undefined, the string should simply say
hostname.example.com
I could do this:
my $foo = ($user) ? "$user\@$host" : $host;
but that seems a bit redundant (I had to type "$user" twice and "$host"
twice).
I could avoid typing "$host" twice with something like:
my $foo = "$user\@" if $user;
$foo .= $host;
but I'm not sure I like that any better...
Does anybody have a more elegant suggestion?
I have two variable, $host and $user (and $user could be undef).
I wish to construct a string such as would be used in an FTP command,
such as:
(e-mail address removed)
However, if $user is undefined, the string should simply say
hostname.example.com
I could do this:
my $foo = ($user) ? "$user\@$host" : $host;
but that seems a bit redundant (I had to type "$user" twice and "$host"
twice).
I could avoid typing "$host" twice with something like:
my $foo = "$user\@" if $user;
$foo .= $host;
but I'm not sure I like that any better...
Does anybody have a more elegant suggestion?