Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

substitution operator

Status
Not open for further replies.

sparc20

Programmer
Mar 13, 2002
56
GB
How can i use the substitution operator for a string variable, lets say

$name="John";

with just the initial of the name and "."

so it will end up

$name="J." ?

many thanks
 
#Save the first char in memory and then find the rest. Replace everything found in first segment by the saved char
and a period

$name = "John";
$name =~ s/^(.).+/$1\./;
print $name;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top