rstone

This is my Rosetta Stone for a small set of computer languages. It assumes that you know all these languages very well, but sometimes use "elif" when you should use "elsif", and vice versa.

A much more awesome Rosetta Stone for Unixes can be found at http://bhami.com/rosetta.html.

Feature Bash Perl Python
For
for I in *; do
for I in {3..8}; do
for (my $i = 3; $i <= 8; $i++) {
for my $i (@arry) {
arry = range(3, 8+1)
for i in arry
Break
break
last;
break
Continue
continue
next;
continue
Else if
elif [ $I -eq 3 ] ... fi
elsif ($i == 3) {
elif i == 3:
String cmp
if [ $S = "abc" ] ... fi
if ($s eq "abc") {
if s == "abc":
Function
function F {
  print $1
sub f {
  my ($i) = @_;
  print $i;
def f (i):
  print(i)
magic input
while (<>) {
import fileinput
for iline in fileinput.input():
regular expression
if (/^Error ([\w.]+):/)
  my $file = $1
import re
mo = re.search(r'^Error ([\w.]+):', iline)
if mo:  # 'mo' = match object
  file = mo.group(1)
print without newline
echo -n 'Prompt: '
print 'Prompt: '
print('Prompt: ', end='')
getopts
while getopts "ht:" OPT; do
  case $OPT in
    h) help ;;
    t) temp="$OPTARG" ;;
    \?) usage ;;
  esac
done
# Make $1 the first positional parm
shift `expr $OPTIND - 1`
use vars cq($opt_h $opt_t);
getopts('ht:') || usage();
if (defined($opt_h)) { help(); }
if (defined($opt_t)) { $temp = $opt_t; }
# @ARGV has options removed, leaving positionals
import getopt
try:
  opts, parms = getopt.getopt(sys.argv[1:], 'ht:')
except getopt.GetoptError as err:
  print(str(err))
  sys.exit(2)
opts_map = dict(opts)
if '-h' in opts_map:
  help()
if '-t' in opts_map:
  temp = opts_map['-t']
# positional parms are in 'parms'

 

Feature C C++ Java
For
for (i = 3; i <= 8; i++)
for (i = 3; i <= 8; i++)
for (i = 3; i <= 8; i++)
Else if
else if (i == 3)
#if ... #elif ... #endif
else if (i == 3)
#if ... #elif ... #endif
else if (i == 3)
Function
void f(int i) {
  printf("%d\n", i);
void f(int i) {
  printf("%d\n", i);
void f(int i) {
  system.out.println(i);

 


Master source files for this page: https://github.com/fordsfords/rstone.