#!/usr/bin/perl -w


#
# Create a string
#
$a = "Hi there";
$name = "Bob";

#
# String concatenation
#
$greeting = $a . " " . $name;
$greeting = "$a $name";

#
# Basic string functions
#
$left = substr($greeting, 0, 3);
$right = substr($greeting, -3, 3);
$mid = substr($greeting, 3, 5);
$len = length($greeting);
print "LEFT = $left MID = $mid RIGHT = $right LEN = $len\n";








#
# Showing string replacement
#
$a = "Hi there how are you";
$a =~ s/Hi/hi/;
$a =~ s/there/they're/;
print "$a\n";

#
#
# Showing string transliteration
$a = "Hi there how are you";
$count = ($a =~ tr/[a-f]/[0-5]/);
print "$a\n";
print "Translated $count letters\n";





# showing rewriting the code
$x = 1;
$a = "\$x = 3; print \"\$x\\n\"";
eval $a;
print $x;

# Creating a new function on the fly
$a = "sub fred { print \"In New Fred\\n\"; }";
eval $a;
&fred;
