using perl in a shell script

my database
deepak 23/12 43536
deepika 23/12 675858

my program

echo "Enter your friend's name"

read FRIEND
found=no
cat database | while read LINE
do
if [ `perl -e ' $LINE =~ /^$FRIEND/' ];then

                             candidate=$\(echo $LINE | cut -d ' ' -f1\)
                             birthday=$\(echo $LINE | cut -d ' ' -f2\)
                             found=yes
                             sleep 1
                             echo "your friend $candidate 's birthday is on $birthday "
                   fi

          done

if [ $found = no ];then

 echo "Sorry no match found"

fi
*****
user gives a name as input..and i want to check in each line of my database file whether there is a match or not and then only do the cut section
***
In this program how can i use perl to check for a match with the user given input

the perl section is not working for me ...i doubt some syntaxial error

end of backquote is missing under if condition...

better way to do the same:

$ret=`perl -e ' $LINE =~ /^$FRIEND/i'`
if [ $ret ];then
...
code
.....

my changed program

#! /usr/bin/bash
set -x
echo "Enter your friend's name"

read FRIEND
found=no
cat database | while read LINE
do
MATCH= `/users/rdlogche/col_solaris/perl -e $LINE =~ "/^$FRIEND/"`
if [ $MATCH ];then

                             candidate=$\(echo $LINE | cut -d ' ' -f1\)
                             birthday=$\(echo $LINE | cut -d ' ' -f2\)
                             found=yes
                             sleep 1
                             echo "your friend $candidate 's birthday is on $birthday "
                   fi

          done

if [ $found = no ];then

 echo "Sorry no match found"

fi

the output with set -x

csbu061 [mhalder] 396: ./bday_search_name
+ echo 'Enter your friend'\''s name'
Enter your friend's name
+ read FRIEND
a
+ found=no
+ cat database
+ read LINE
++ /users/rdlogche/col_solaris/perl -e a 12/23 23233 '=~' '/^a/'
+ MATCH=
+ '[' ']'
+ read LINE
++ /users/rdlogche/col_solaris/perl -e b 23/34 8474674 '=~' '/^a/'
+ MATCH=
+ '[' ']'
+ read LINE
++ /users/rdlogche/col_solaris/perl -e c 34/45 64784849 '=~' '/^a/'
+ MATCH=
+ '[' ']'
+ read LINE
++ /users/rdlogche/col_solaris/perl -e d 45/23 74847464 '=~' '/^a/'
+ MATCH=
+ '[' ']'
+ read LINE
+ '[' no = no ']'
+ echo 'Sorry no match found'
Sorry no match found

why do you need to use Perl for that?

#!/bin/bash
set -x
echo "Enter your friend's name"
read FRIEND
found=no
while read LINE
do
 case $LINE in 
 ${FRIEND}* ) 
     CANDIDATE=$(ECHO $LINE | CUT -D ' ' -F1)
     BIRTHDAY=$(ECHO $LINE | CUT -D ' ' -F2)
     FOUND=YES
     SLEEP 1
     ;;
 * ) echo "DSFSDFS";;
 esac
done < "file"
...

ghostdog74

thanks for the sollution but if at all i want to do it using perl can it be done the way i have shown
and if so where the error is occurring

One problem is that when you type

perl -e ' $LINE =~ /^$FRIEND/'

you pass the string in single quotes to Perl to executed. The single quotes prevents the shell from expanding those variables. Perl just sees two (unitiialised) Perl variables i.e. empty strings.
Another is, what do you expect to capture from the backticks? You haven't told Perl to print anything, Try running that Perl command on the command line on its own.

Basically, ghostdog74 is right: this would be easier if it were all done in one language.