Perl isn't a statically (or even strongly) typed language. It generally tries to do "something sensible" (or "Do What I Mean" - abbreviated as DWIM) with data.

If you're trying to use a string as a number, it will do a string->numeric conversion (handling leading spaces and stopping at the first non-digit).

This behaviour is generally useful and time-saving. One places where you may get caught out by it is in boolean true/false tests. All the following are false (nothing is printed):

print "a" if 0; print "b" if ""; print "c" if "0";
the one which surprises people the most is "c" not being printed.

Dynamic languages can require a bit of mental adjustment, C, C#, C++ and java programmers are used to having the compiler catch certain classes of errors. Perl will only catch similar errors at runtime (and will work around others as we've just seen).

For those that like dynamic languages, the general view is that you are more productive in them (since type declarations littering your code make it more brittle - i.e. harder to change and adapt it) and that computer-checked correctness is better achieved via unit testing, to verify the dynamic behaviour.

There is a well-established culture of unit testing in perl, with good modules to support it's use and most (all?) CPAN modules including a test suite.

Lastly, I think perl6 will bring such (optional) type annotations to the language, but I'm not sure and don't know the details.


In reply to Re: implicit data type exchange by jbert
in thread implicit data type exchange by xiaoyafeng

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.