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...
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |