Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I don't see your pure-Perl "Modification of a read-only value..." result on ActiveState 5.8.9 and Strawberry 5.14.4.1 (Update: likewise Strawberries 5.10.1.5 and 5.12.3.0), but there's something else I don't understand:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dumper -le "sub modify { $_ = 5 for @_; } ;; my @a; @a = (undef) x 5; ;; modify(@a); print Dumper \@a; ;; my @b; $#b = 4; ;; modify(@b); print Dumper \@b; ;; my @c; $#c = 4; $c[ $#c ] = undef; ;; modify(@c); print Dumper \@c; " $VAR1 = [ 5, 5, 5, 5, 5 ]; $VAR1 = [ undef, undef, undef, undef, undef ]; $VAR1 = [ undef, undef, undef, undef, 5 ];
Arrays @b and @c are still unwriteable (or at least unwritten, at least in part), but in a different way.   ?!?

Update: Taking the  @_ argument list out of the equation, I get expected results (thank Larry!) for the problematic cases above (for all Perl versions listed in the first paragraph):

c:\@Work\Perl\monks>perl -wMstrict -MData::Dumper -le "my @b; $#b = 4; ;; $_ = 5 for @b; print Dumper \@b; ;; my @c; $#c = 4; $c[ $#c ] = undef; ;; $_ = 6 for @c; print Dumper \@c; " $VAR1 = [ 5, 5, 5, 5, 5 ]; $VAR1 = [ 6, 6, 6, 6, 6 ];


Give a man a fish:  <%-{-{-{-<


In reply to Re^5: What does my @x= (undef)x7; do? by AnomalousMonk
in thread What does my @x= (undef)x7; do? by gepebril69

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-18 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found