Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w use strict; use Data::Dumper; use Scalar::Readonly ':all'; my $count = 0; my @savearr = (); eval { sub make { save('begin '.$count++.' end'); } sub save { readonly_on($_[0]); #comment this out push(@savearr, \$_[0]); } for(0..3) { make(); } print(Dumper(\@savearr)); }; if($@) { print("failed in eval with\n\"$@\"\n".Dumper(\@savearr)); }
readonly on
C:\Documents and Settings\Owner\Desktop>perl failed in eval with "Modification of a read-only value attempted at line 9. " $VAR1 = [ \"begin 0 end" ]; C:\Documents and Settings\Owner\Desktop>
readonly off
C:\Documents and Settings\Owner\Desktop>perl $VAR1 = [ \"begin 0 end", \"begin 1 end", \"begin 2 end", \"begin 3 end" ]; C:\Documents and Settings\Owner\Desktop>
This is the Perl equivalent of an XS problem I am having. If I turn on readonly, on the next loop run it dies. But this is a second run, with a new value. Old value when out of scope (but still lives in the @savearr). If I comment out the readonly, and it reaches the end, you will see 4 references, to the same, or is that different scalar? Yet the readonly flag proves that its the same scalar and it stays around AFTER it goes out of scope. But the array proves 4 different scalars. Isn't that a violation of what the my keyword and lexical system does? Whats going on here?

In reply to lexicals are all the same scalar and never go out of scope? by patcat88

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: (5)
    As of 2018-05-27 12:56 GMT
    Find Nodes?
      Voting Booth?