I have a piece of codes constructing an email sender:
The blue section does not look pretty to me. Is there a way to enhance it using one-liner?
Many thanks.
Code:
sub getSender {
my $host = hostname;a # use Sys::Hostname;
my $domain = 'xyz.com';
my $char = '.';
my $from;
if($host =~ /$domain/) {
# hostname() may return a string like foo.bar.xyz.com and in this case
# we want to return foo@bar.xyz.com [COLOR=blue]
my $ind = index($host, $char);
my $p1 = substr($host, 0, $ind);
my $p2 = substr($host, $ind+1);
$from = $p1.'@'.$p2;[/color]
}
else {
# hostname() simply returns 'foo'
$from = $host.'@'.$domain;
}
return $from;
}
The blue section does not look pretty to me. Is there a way to enhance it using one-liner?
Many thanks.