I've never seen p and P in pack before and I can't figure out what they actually do (as in I have read the docs, tried some code but still don't understand). I thought
#! /usr/bin/perl -l $a="fergal"; $p=\$a+0; print $p; $x=unpack("P9", pack 'j', $p); print length($x);
might read the first 9 bytes of the SV structure for $a but it just has length 0. Do you have a demo?

Anyway, this is not really what I'm getting at. You can't use this to try treat the memory for a perl array variable as a perl string variable, at most this allows you to treat the memory for a perl array variable as the C string inside a perl string variable.

Imagine you could twiddle the pointer inside a perl reference value, it still wouldn't be weakly typed. If you point the ref at a bit of memory that contains a perl string variable then it will become a string-ref if you point it at an array variable it will become an array-ref (I think this is the case although I'm not an XS whizz and I don't have time to test it as I'm going on holidays in an hour!). So for perl to be weakly typed I would have to wrong and the language would have to have this reference twiddling feature built in.


In reply to Re^3: Perl 6: Static/Dynamic Strong/Weak Type Systems by fergal
in thread Perl 6: Static/Dynamic Strong/Weak Type Systems by tomazos

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.