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 C Bash Perl Python
For
for (i=0; i<10; i++) {...}
for I in *; do
for I in {3..8}; do
for (my $i = 3; $i <= 8; $i++) {
for my $i (@arry) { # same as foreach
arry = range(3, 8+1)
for i in arry
Break
break;
break
last;
break
Continue
continue;
continue
next;
continue
else if
else if ( i == 3 ) ...
elif [ $I -eq 3 ] ... fi
elsif ($i == 3) {
elif i == 3:
String cmp
if (strcmp(s,"abc") == 0)
if (strncmp(s,"abc",sizeof(s)) == 0)
if [ $S = "abc" ] ... fi
if ($s eq "abc") {
if s == "abc":
Find char in string
char *p=strchr(s, c);
p=strnchr(s, c, sizeof(s));
i=index(s, c);
i=index(s, c, s_offset);
Function
void f(int i) {
  printf("%d\n", i);
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 echo $ILINE |
  grep "Error " >/dev/null
then echo "match"
fi
if (/^Error ([\w.]+):/)
  my $file = $1
import re
mo = re.search(r'^Error ([\w.]+):', iline)
if mo:  # mo is match object
  file = mo.group(1)
print without newline
printf("Prompt: ');
echo -n 'Prompt: '
print 'Prompt: '
print('Prompt: ', end='')
getopts
while((opt=getopt(argc,argv,"ht:")!=EOF){
  switch (opt) {
    case 'h': help(); break;
    case 't': t = atoi(optarg); break;
    default: usage();
  }
}
while (optind < argc) {
  printf("positional:%s\n",argv[optind]);
}
while getopts "ht:" OPT; do
  case $OPT in
    h) help ;;
    t) temp="$OPTARG" ;;
    \?) usage ;;
  esac
done
# First positional to $1
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: options gone, positionals left
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.