Problems? Is your data what you think it is? | |
PerlMonks |
Array spliceby code-ninja (Scribe) |
on Aug 30, 2013 at 07:11 UTC ( [id://1051556]=perlquestion: print w/replies, xml ) | Need Help?? |
code-ninja has asked for the wisdom of the Perl Monks concerning the following question:
This may seem a stupid question but one of the Monastery's quotes say that "A stupid question is a question not asked."
Having said that, I'm working on making Perl my preferred programming language. Right now, I'm an accomplished C programmer but I want some change... whatever, back to the point.
the "splice" line is essentially push(@arr, @new) right? From C perspective, it is basically strcpy(arr, new) where "arr" and "new" are C arrays. Again from a C perspective, let *(arr + n) (for some n) point to the location past the last entry of array "arr". If I say strcpy((arr + n), new) I'll get a seg fault (obviously!). But when I do splice(@arr, scalar(@arr), n, @new) I do not get the seg fault. Why I think it should seg fault?Simple, scalar(@arr) takes me to the last position in the array "arr" and the third argument to splice is the length. Now, my length is exceeding the length of the array "arr" hence I'm trying to access the something out of bounds, therefore it should seg fault. Whats the story, morning glory?!
Back to
Seekers of Perl Wisdom
|
|