problem with converting time using perl

Hello,

I have an AIX 5.3 system and i created a script to get the last login of users.
The script goes like this:

 
LAST_LOGIN=`lsuser -a time_last_login $cur_user` 
TIME_LOGIN=`perl -e 'print scalar localtime("$LAST_LOGIN")'`

Actually what i do in these two lines is to set a variable (LAST_LOGIN) which is the return of

lsuser -a time_last_login

command. The reason i am doing this is because the return of this command is in a form like this 1304942474 which is not a human date and time and i need to convert it later on.
That is what i am doing in the second line using perl -e to convert this value. The weird thing is that if i simply run in the command line the following command

perl -e 'print scalar localtime(1304942474)'

i get the output Mon May 9 15:01:14 2011 which is correct i suppose. But when i run it through a script replacing the value (1304942474) with ("$LAST_LOGIN") then i get the output
Thu Jan 1 02:00:00 1970 which is obviously wrong.

Any idea what is causing this behaviour and how i should do it to work properly?

Thank you for your attention

You have prevented interpolation of $LAST_LOGIN in the Perl call and so it sees it as an undeclared perl variable to be autovified to null, "" oe 0 depending on how it is accessed, try calling the following with the LAST_LOGIN value set in the shell rather than substituting the value.

perl  -Mstrict -e 'print scalar localtime ($LAST_LOGIN)'

To access environment variables in Perl scripts use the %ENV hash in your script

perl   -e 'print scalar localtime ($ENV{LAST_LOGIN)}'

Thank you for your help

i tried

perl   -e 'print scalar localtime ($ENV{LAST_LOGIN)}'

and it worked fine!