perl - How to add a character before a specific symbol in a variable? -
i have user defined variables user@domain.com
using perl need add "sc" @ end of user , before @ symbol.
so if:
$user = "user@domain.com" $string = "sc"
i need come out result of
$user-id = "usersc@domain.com"
any appreciated.
$user =~ s/(?=@)/sc/;
or
$user =~ s/@/sc@/;
or
$user =~ s/^[^@]*\k/sc/; # assumes "@" present.
of course, none of work if $user
doesn't contain correct string begin with.
$user = "user@domain.com";
is same as
$user = "user" . join($", @domain) . ".com";
given @domain
doesn't exist, that's same as
$user = "user.com";
always use use strict; use warnings;
! want
my $user = "user\@domain.com";
or
my $user = 'user@domain.com';
to create var $user
string user@domain.com
.
Comments
Post a Comment