appending space to variable

Hi
I need to write a script where there the user enters 3 input parameter
variable
number
the program should ask the user left or right
if it is left , the number specified that many spaces should be added to the value in front of the value and saved in the samee variable itself and if it is right that many number of spaces should be added in the right side

for ex
variable = vivek
number =4
and when user echo $variable output should be
if user opts for right then output = (4 spaces in front)vivek
if user opts for left then output =vivek(4 spaces in back)

sample snippet in perl

$indendSpace += 2;
$spaceVar = " " x $indendSpace;

$var =~ s/^/$spaceVar #at the start
$var =~ s/$/$spaceVar #at the end

need it in korn shell

Thanks but need it in korn shell

Code snippets in ksh-93

$pad="    "
$var="vivek"
$ newvar=$pad$var
$ echo $newvar
vivek
$ echo ${#newvar}
9
$ echo "$newvar"
    vivek
$ L=9
$ new=$(printf "%${L}s" "$var" )
$ echo "$new"
    vivek
$
#!/bin/ksh

echo "Input variable: \c" ; read var
echo "Input number: \c" ; read pad
echo "Input Left or Right padding (L or R): \c" ; read lr

lr=$(echo $lr | tr '[a-z]' '[A-Z]')

if [ "$lr" != "R" ] && [ "$lr" != "L" ]
then
        echo Invalid padding $lr !
        exit
fi

while [ $pad != 0 ]
do
        if [ "$lr" = "R" ]
        then
                var=$var" "
                let pad=$pad-1
        else
                var=" "$var
                let pad=$pad-1
        fi
done

echo "[$var]"