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.
> Hi help-cfengine,
>
> Running community 3.0.3.
>
> Given a string, is there a way to address the characters in the string?
>
> splitstring() seems to work fine as long as there is a delimiter, e.g.
>
> vars:
> "words" slist => splitstring("foo:bar:baz", ":", 3);
>
>
> But it doesn't seem to function quite analogously to Perl/Python's
> split. For example,
>
> vars:
> "chars" slist => splitstring("word", "", 4);
>
>
> doesn't return an error, but the "chars" slist doesn't seem to be
> defined, either. Using "." and "[.]" as regexps doesn't do it, either.
>
> Am I barking up the wrong tree?
>
> The reason for this is that we have "hashed" home directories to create
> - e.g. homedirs for joe and frank are:
>
> /users/j/o/joe
> /users/f/r/frank
>
> Hope you can give me some pointers.
>
> Regards,
> Jim
>
> --
> Jim Lawson
> Systems Architecture & Administration
> Enterprise Technology Services
> University of Vermont
> Burlington, VT USA
>
>
> _______________________________________________
> Help-cfengine mailing list
> [email protected]
> https://cfengine.org/mailman/listinfo/help-cfengine
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine