I don't know the slightest bit of Perl and have to fix a bug in a Perl script.
Given a variable $myvar
which contains a string, if the first character is a dot, replace it with "foo/bar".
How can I do this?
(Bonus points if you can guess the bug)
$myvar =~ s+^\.+foo/bar+ ;
You can use substr:
substr($myvar, 0, 1, "foo/bar") if "." eq substr($myvar, 0, 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With