Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Sorting array, getting modification of read-only value error

by thundergnat (Deacon)
on Nov 28, 2012 at 19:54 UTC ( #1006095=note: print w/ replies, xml ) Need Help??


in reply to Sorting array, getting modification of read-only value error

What tobyink++ said. You are filling your @S array starting at index 1 ($v=1;). But arrays are (by default) zero indexed, so $S[0] has nothing in it. Sort then tries to auto-vivify values for $S[0] and gives you an error. Minimal "fix" is to index $v from 0.

You have many, many other sub-optimal things in there too though.


Comment on Re: Sorting array, getting modification of read-only value error
Re^2: Sorting array, getting modification of read-only value error
by myelinviolin (Novice) on Nov 28, 2012 at 21:00 UTC
    This worked!! Thank you so much! This makes so much sense with the autovivication now. There WAS a gap in the array, so that's why it couldn't sort it. I know I do things differently than most people, but for me, readability and ease of use trump inefficiency any day. As long as the program runs without any wait periods, then it's ok with me.

      ...I don't think the grandparent was talking about inefficiency when he said "sub-optimal"...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006095]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2014-09-19 01:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls