Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Perl without its internal 'magic' implementation is essentially no longer Perl.

Here's some of the features of perl that would no longer work in sections of code where magic was disabled:

$1, $2, et al, and in fact most other special variables, such as  $., $!, %ENV, %SIG, @ISA etc;

while (/.../g) (/g match in scalar context);

weak references;

ties; so for example this stops working: use Config; if ($Config{foo}) ...

the taint mechanism;

$#array, keys %hash, substr, vec in lvalue context;

foo($hash{nonexist}), where the element is only vivified if foo() assigns a value to $_[0];

It would also interfere with offset caching on utf8 strings, meaning that for example //g on long strings will go quadratic on length.

And of course if you write a function which is allowed to be called by others, then you have to allow that @_ may contain magic values which won't work properly if you've disabled magic in your function. Similarly, the return value you receive from other functions or perl builtins and ops may contain magic.

In short, all but the most trivial of perl code requires magic to be enabled.

Note also that you can't have just 'low' amounts of magic; in a particular section of code you either perform a check on each SV before you access it to see if it has any magic attached (and after you update it), or you don't. So its all or nothing.


In reply to Re: Perl 5 Optimizing Compiler, Part 9: & The Low-Magic Perl Commandments by dave_the_m
in thread Perl 5 Optimizing Compiler, Part 9: & The Low-Magic Perl Commandments by Will_the_Chill

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (9)
    As of 2018-06-21 10:36 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (118 votes). Check out past polls.