Reputation: 23
I have a user defined variables that is a [email protected]
Using perl I need to add "sc" at the end of user and before the @ symbol.
so if:
$user = "[email protected]"
$string = "sc"
I need to come out with the result of
$user-id = "[email protected]"
Any help would be appreciated.
Upvotes: 2
Views: 416
Reputation: 386501
$user =~ s/(?=@)/sc/;
or
$user =~ s/@/sc@/;
or
$user =~ s/^[^@]*\K/sc/; # Assumes "@" will always be present.
Of course, none of those will work if $user
doesn't contain the correct string to begin with.
$user = "[email protected]";
is the same as
$user = "user" . join($", @domain) . ".com";
Given that @domain
doesn't exist, that's the same as
$user = "user.com";
Always use use strict; use warnings;
! You want
my $user = "user\@domain.com";
or
my $user = '[email protected]';
to create var $user
with the string [email protected]
.
Upvotes: 5