title: Why do people say Perl is dynamically typed?
body: <p>Statically typed vs dynamically typed has been asked repeatedly on stackoverflow, for example <a href="https://stackoverflow.com/questions/1517582/what-is-the-difference-between-statically-typed-and-dynamically-typed-languages">here</a>.</p>
  
  <p>The consensus seems to be (quoting from the top answer of the above link):</p>
  
  <blockquote>
    <p>A language is statically typed if the type of a variable is known at compile time.</p>
  </blockquote>
  
  <p>And a dynamic language:</p>
  
  <blockquote>
    <p>A language is dynamically typed if the type is associated with run-time values, and not named variables/fields/etc.</p>
  </blockquote>
  
  <p>Perl seems to be statically typed by this (or other common definitions of static/dynamic typing). It has 3 types: scalar, array, hash (ignoring things like references for simplicity's sake). Types are declared along with variables:</p>
  
  <pre class="lang-perl prettyprint-override"><code>my $x = 10;                   # declares a scalar variable named x
  my @y = (1, 2, 3);            # declares an array variable named y
  my %z = (one =&gt; 1, two =&gt; 2); # declares a hash variable named z
  </code></pre>
  
  <p>The <code>$</code>, <code>@</code> and <code>%</code> above tell Perl which type you want; I'd count this as a form of explicit typing.</p>
  
  <p>Once <code>x</code> has been declared as a scalar, as above, it's impossible to store a non-scalar value in <code>x</code>:</p>
  
  <pre class="lang-perl prettyprint-override"><code>$x = @y;                      # x is now 3
  </code></pre>
  
  <p>Will convert <code>y</code> to a scalar (in Perl, array to scalar conversion result in the length of the array). I blame this on weak typing (Perl very liberally allows conversions between its 3 types), rather than dynamic typing. </p>
  
  <p>Whereas in most statically typed languages, such an assignment would be an error, in Perl it is ok because of implicit conversions (similar to how <code>bool x = 1;</code> is fine in C/C++, but not in Java: both are statically typed, but Java is more strongly typed in this case). The only reason this conversion happened at all in Perl is because of the type of <code>x</code>, which again suggests Perl is statically typed.</p>
  
  <p>Another argument people have against Perl being statically typed is that floats, ints, and strings are all stored in the same type of variable (scalars). But this really has nothing to do with static or dynamic typing. Within Perl's type system (which has only 3 types), there is no difference between floats, ints and strings. These all have type scalar. This is similar to saying C89 isn't statically typed because it used the <code>int</code> type to represent both ints and bools. </p>
  
  <p>Obviously, this line of reasoning is ridiculous. Perl has very little in common with what most people think of as statically typed languages like C/C++, Java, OCaml, etc.</p>
  
  <p>My question is, what's <em>wrong</em> with this line of reasoning? </p>