Main Content

Variable storage - Perl, Tcl and Python compared

Archive - Originally posted on "The Horse's Mouth" - 2009-10-08 06:04:44 - Graham Ellis

From Monday to Wednesday, I was teaching Python to a group of delegates at a company where I have previously taught Tcl and Expect and Perl. And this interesting diagram shows just what a contrast there is between the three languages right from the start - in terms of how data is stored into variables!

In Tcl, all data is stored a strings so the number 21 would be 2 bytes - the character 2 followed by the character 1.

In Perl, you have a much more 'traditional' model where the name of the variable - which has a leading $ - may be considered to be a direct label on the storage element

And in Python, everything is an object, so your variable name contains a reference to a location on the heap at which the data is stored.