let's say there is a script
Code: Select all
/interface ethernet
{
:local drxByteCount [:tostr [get value-name=driver-rx-byte ether1]];
:local length [:len $drxByteCount];
:put ("drxByteCount variable is of type ".[:typeof $drxByteCount]);
:put ("drxByteCount variable is of len ".$length);
:put $drxByteCount;
:put ("first element of string with index 0 is ".[:pick $drxByteCount 0]);
:put ("last element of string with index ".($length-1)." is ".[:pick $drxByteCount ($length-1)]);
:put ("but picking from 0 to 12 gives ".[:pick $drxByteCount 0 ($length-1)]);
:put ("and picking from 0 to".$length." gives ".[:pick $drxByteCount 0 $length]);
}
[admin@TK] > system script run script3
drxByteCount variable is of type str
drxByteCount variable is of len 13
2 390 361 529
first element of string with index 0 is 2
last element of string with index 12 is 9
but picking from 0 to 12 gives 2 390 361 52
and picking from 0 to13 gives 2 390 361 529
[admin@TK] >
what am i missing here ? This looks like some kind out of bounds memory violation type error. Why is start index inclusive and end index exclusive ? This is imo very confusing to anyone who ever programed in C or C++