Hi Dan,

Thanks for the tip.  \B does seem to work in the way that I expected the
null pattern to (although I understand the subtle difference you point
out.  Fortunately, our usernames shouldn't have any word boundaries in
them.)

The other issue that I am running into is that it seems that slists
cannot be indexed - calling getindices on an slist does not seem to
return another slist.  So only arrays have indices (?)

I attempted:

vars:
         "chars" slist => splitstring("word", "\B", 4);

reports:
    cfengine_3::
        "The first letter in word is $(chars[0])"

But that doesn't seem to work.  So, per your suggestion, I tried
regextract - according to the online docs, regextract will create an
array, which I may be able to use in this way.  Problem is...

> # cf-agent -f ./understanding_slist.cf -I -K
> cf3:./understanding_slist.cf:24,83: Unknown built-in function
> regextract(), near token ')'
Is regextract() only available after 3.0.3?

Jim

On 2/26/10 2:13 PM, daniel.kl...@cfengine.com wrote:
> Jim-
>
> You're right, splitstring does not split on every character (and maybe it
> should if you specify a null pattern).  And you missed on "." (because that
> makes every character a separator, and then there are no characters to
> separate) and on "[.]" (because a '.' in a [character class] is just a dot,
> and there are no dots in your string.  But here's something that will get
> you closer:
>
> vars:
>     "chars" slist => splitstring("word", "\B", 4);
>
> (look in the Perl manual for the reason :-)  This works fine if you only have
> alphanumeric characters in your string (a-zA-Z0-9_).  However, it will NOT 
> work
> right if you try to split "foo:baz:bar".
>
> Look at regextract, too - that may be another way of accomplishing what you
> want - in case you need to address more complicated strings to split.
>
> -Dan
>
> P.S.  \b means the place between a \w and a \W character.  \B means the place
> between two \w or two \W characters.
>
>   

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to