My programming rosetta stone.
• rstone
• My Rosetta Stone
• License
• Introduction
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++) { foreach my $i (@array) { |
for i in array |
Break | break; | break | last | break |
Continue | continue; | continue | next; | continue |
Else if | else if () | elif [ ] | elsif () | elif |
String cmp | if (strcmp(s,"abc")==0) | if [ "$S" = "abc" ] | if ($s eq "abc") | if s == "abc" |
Find char | p=strchr(s, c); p=strnchr(s, c, l) |
n.a. | i=index(s, c); i=index(s, c, s_offset); |
??? |
Function | void f(int i) { | F () {; $1 | sub f { my ($i) = @_; | def f (i) |
magic input | n.a. | n.a. | while (<>) { | import fileinput for iline in fileinput.input(): |
regexp | n.a. | if echo $S | grep "pat" >/dev/null | if (/pat/) if ($s=~/pat/) |
import re mo = re.search(r'pat', s) if mo: |
print no nl | printf("prompt: "); | echo -n "prompt: " | print "prompt: "; | print("prompt: ", end='') |
getopts | c_linux_getopts.c | bash_getopts.sh | perl_getotps.pl | python_getotps.py |
threads | c_linux_threads.c | bash_threads.sh | JavaThreads.java | python_threads.py |
Feature | C | Bash | Perl | Python |
I want there to be NO barriers to using this code, so I am releasing it to the public domain. But "public domain" does not have an internationally agreed upon definition, so I use CC0:
Copyright 2012,2024 Steven Ford http://geeky-boy.com and licensed "public domain" style under CC0:
To the extent possible under law, the contributors to this project have waived all copyright and related or neighboring rights to this work. In other words, you can use this code for any purpose without any restrictions. This work is published from: United States. The project home is https://github.com/fordsfords/rstone
To contact me, Steve Ford, project owner, you can find my email address at http://geeky-boy.com. Can't see it? Keep looking.
Sometimes its hard remember which programming language uses which syntax. For example, "endif" -- does Bourne shell use that? Or does it use "fi"? Spoiler: "fi" is shell. So who does use "endif"? C pre-processor conditionals. :-)
Thanks to http://bhami.com/rosetta.html for making a far more useful site (and coming up with an awesome name).
Master source: https://github.com/fordsfords/rstone