Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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 ro.pl failed in eval with "Modification of a read-only value attempted at ro.pl line 9. " $VAR1 = [ \"begin 0 end" ]; C:\Documents and Settings\Owner\Desktop>
readonly off
C:\Documents and Settings\Owner\Desktop>perl ro.pl $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

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (5)
    As of 2014-07-29 04:47 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (211 votes), past polls