So I was a bit bored and had a flash of inspiration on how to convert strings to all lowercase or uppercase with Perl. Sure, you could use the built in lc() and uc() methods, but I wanted to do something a bit more fun.
use strict;
use warnings;
my $test;
my $x;
my ( $uppercaseTest, $lowercaseTest );
my $character;
$test = $ARGV[0];
$x = 0;
unless
( defined $test
)
{
$test = "pONy";
}
($uppercaseTest, $lowercaseTest) = ("", "");
while
( $x < length $test
)
{
$character = substr $test, $x, 1;
if
( $character =~ m/[a-z]/i
)
{
$uppercaseTest .= $character | " ";
$lowercaseTest .= $character & "_";
}
else
{
$uppercaseTest .= $character;
$lowercaseTest .= $character;
}
$x++;
}
print $uppercaseTest, "\n";
print $lowercaseTest, "\n";
So I realize this could be simpler with the built in functions for uppercase and lowercase conversion, but I felt like having fun. I hope you guys get what's going on. If you don't, feel free to ask.