Perl: Concatenating Text and More - Transformers...More than Meets the Eye (
Page 4 of 4 )
There are a number of built-in Perl functions that allow you to do crazy things with text. Among those are ways to manipulate the case of characters, changing the first letter to upper/lower case, the whole string to upper/lower case, etc. Here they are in a program:
#!/usr/bin/perl
$thingOne="james";
$thingtwo="PAYNE";
print $thingOne . "\n";
print ucfirst($thingOne);
print "\n";
print uc($thingOne);
print "\n\n";
print $thingtwo;
print "\n";
print lcfirst($thingtwo);
print "\n";
print lc($thingtwo);
This will result in:
james
James
JAMES
PAYNE
pAYNE
payne
If functions aren't your thing, you can also use special characters to achieve the same effect:
#!/usr/bin/perl
$thingOne="james";
$thingtwo="PAYNE";
print "l$thingtwo";
print "\n\n";
print "u$thingOne";
print "\n\n";
print "L$thingtwo IS MY LAST NAME E U$thingOneE is the first.";
This gives us the result:
pAyne
James
payne is my last name JAMES is the first.
A few things to note: the "l" and "u" act as lcfirst and ucfirst, respectively, while the "L" and "U" make everything following it uppercase until it reaches the "E", which signals an end to the special character.
Well unfortunately we did not get to cover every bit of string manipulation that I wanted to, but never fear: we'll get to that in another article. Maybe even the next one, where I will also cover ways to manipulate numbers.
Till then...