pythonizer
pythonizer copied to clipboard
Translator (or more correctly transcriber) from Perl to Python
If the perl variables happen to match python keywords, they should be escaped using a trailing '_'. Here are the ones that need to be escaped: `False None True and...
perl eval block should generate a try block instead of a syntax error. Catch any exception and set the message in `$@` else clear that special variable. Change `die` to...
Variable references in interpolated strings with ${var} generate bad code. For example: $tmdate = "${year}_${month}_${day}"; produces: tmdate=f"{[year]}_{[month]}_{[day]}" instead of: tmdate=f"{year}_{month}_{day}"
qw/strings/ are not translated due to a simple typo in %TokenType (Perlscan.pm). Change `wq` to `qw` to fix it.
perl simple constant definition sub doesn't generate proper code. For example: sub false { 0; } generates: def false(perl_arg_array):
Referencing the special variable `$"` gives an unclosed string error.
Arrays should be interpolated in strings, for example: $s = "array is @array, hash is @{[%hash]}" sets s to exactly that string - it should include the contents of array...
Enh: Change a call to GetOptions() with constant string arguments into replacement calls using argparse.
Perl `@ARGV` does not contain the script reference at index 0, while python `sys.argv` does, so references should be replaced with `sys.argv[1:]`.
Dereferencing an array or hash ref generates bad python code. For example: @three = @{$options{three}}; Generates: three=@[options['three']] instead the dereference should be ignored and this code should be generated: three=options['three']