Help needed with translating perl to python

vj vinjvinj at gmail.com
Tue Jun 26 11:17:06 EDT 2007


I posted too soon:

> Statement 1:
>   my $today = sprintf("%4s%02s%02s", [localtime()]->[5]+1900,
> [localtime()]->[4]+1, [localtime()]->[3]) ;

1. is localtime the same as time in python?
2. What does -> ? do in perl?
3. What is 'my'

> Statement 2:
>   my $password = md5_hex("$today$username") ;

is md5_hex the same as md5.new(key).hexdigest() in python?

> $msglen = bcdlen(length($msg)) ;

1. here the funciton is being called with the length of variable msg.
However the function def below does not have any args

> sub bcdlen {
>   my $strlen = sprintf("%04s", shift) ;
>   my $firstval = substr($strlen, 2, 1)*16 + substr($strlen, 3, 1) ;
>   my $lastval  = substr($strlen, 0, 1)*16 + substr($strlen, 1, 1) ;
>   return chr($firstval) . chr($lastval) ;
>
> }

2. What does shift do above?
3. is the '.' operator just + in python?

Thanks,

Vineet






More information about the Python-list mailing list