CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Modification of non-creatable array value attempted

 



yleberre
New User

Sep 29, 2015, 9:23 AM

Post #1 of 4 (1276 views)
Modification of non-creatable array value attempted Can't Post

Hello,

I run this piece of code :


Code
     1	@lines = split (/\n/, $read_buffer, -1); 
2 $lines[0] = $residu . $lines[0] if (defined $residu);
3 if ($read_buffer =~ /\n$/) {
4 undef $residu;
5 } else {
6 $residu = $lines[$#lines];
7 $lines[$#lines] = '';
8 }


This code is heavily used among many identical processes on several hosts (same hardware, same OS : SunOS 5.10 x86, same version of perl : 5.8.4 : default Solaris package) and, on a specific host, from time to time (rarely), one process aborts with the error 'Modification of non-creatable array value attempted' on line 7 with the value of index -1.

What have i missed ?
How $#lines may be modified between line 6 and line 7 ?

Thanks for your advices.
Y. Le Berre


BillKSmith
Veteran

Sep 29, 2015, 6:52 PM

Post #2 of 4 (1268 views)
Re: [yleberre] Modification of non-creatable array value attempted [In reply to] Can't Post

The following code duplicates the problem. You can see that it happens when the array is not defined.

Code
use strict; 
use warnings;
my @lines;
my $residu = $lines[$#lines];
$lines[$#lines] = '';

Output:

Code
Modification of non-creatable array value attempted, subscript -1 at C:\Users\Bi 
ll\perl\guru\yleberre.pl line 5.

Good Luck,
Bill


yleberre
New User

Sep 30, 2015, 11:33 AM

Post #3 of 4 (1263 views)
Re: [BillKSmith] Modification of non-creatable array value attempted [In reply to] Can't Post

I thought line 1 of initial script :


Code
@lines = split (/\n/, $read_buffer, -1);


was sufficient to populate systematically @lines array but split function documentation indicates :


Quote
split /PATTERN/,EXPR,LIMIT
...
Note that splitting an EXPR that evaluates to the empty string always produces zero fields, regardless of the LIMIT specified.
...


So, I must deal with empty $read_buffer before assigning @lines.

Thanks.
Y. Le Berre


FishMonger
Veteran / Moderator

Oct 1, 2015, 8:56 AM

Post #4 of 4 (1235 views)
Re: [yleberre] Modification of non-creatable array value attempted [In reply to] Can't Post

Please post more of your code to give us more context to see why you chose to populate the array in this way and if you can, post sample input data.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives