Why doesn’t the rules file split function preserve field order?

I have a rules file and need to pass a set of fields via a single token using a delimiter.

However, when we use the split function, it ignores the null values, so the field numbers are different from tokens where there are no null values.

For example:

File: split.rules
array MyArrayOfValues

$1_text = “f1|f2|f3||f5|f6|f7|f8|f9|f10”

if (exists($1_text))
{

$input = $1_text

$n = split( $input, MyArrayOfValues, “|” )

foreach ( n in MyArrayOfValues )
{
log(warn,”MyArrayOfValues = ” + n + ‘:’ + MyArrayOfValues[n])
}

}
#EOF

will create token values like:

MyArrayOfValues = 1:f1
MyArrayOfValues = 2:f2
MyArrayOfValues = 3:f3
MyArrayOfValues = 4:f5
MyArrayOfValues = 5:f6
MyArrayOfValues = 6:f7
MyArrayOfValues = 7:f8
MyArrayOfValues = 8:f9
MyArrayOfValues = 9:f10

But we need the values to be in their own field array value like :

MyArrayOfValues = 1:f1
MyArrayOfValues = 2:f2
MyArrayOfValues = 3:f3
MyArrayOfValues = 4:
MyArrayOfValues = 5:f5
MyArrayOfValues = 6:f6
MyArrayOfValues = 7:f7
MyArrayOfValues = 8:f8
MyArrayOfValues = 9:f9
MyArrayOfValues = 10:f10

Related:

  • No Related Posts

Leave a Reply