On Thu, Feb 16, 2012 at 02:50:27PM -0800, Aaron Nicoli wrote:
> Hi all,
> 
> Been searching the net for a few hours now.
> I have a basic operation I wish to perform but, cannot find examples
> close enough to what I'm after to implement it myself.
> 
> This is what I want to do:
> 
> $version = '10.2.0'
> 
> I want to manipulate the string to make a new var ($cutversion), equal
> just 102.
> 
> For example in perl (since I know it):
> 
> $version = '10.2.0';
> if ($version =~ /^(\d+)\.(\d+).*$/) {
>    $cutversion = $1 . $2;
> }
> 
> Any help?

There are not that many string manipulating functions in puppet itself
but you can always build your own [1] or have a look at the puppet-std
[2]

However your problem can be solved with the build-in function regsubst
which can be found in the function reference [3]

This should work (while untested)

    $cutversion = regsubst($version, '^(\d+)\.(\d+).*$', '\1\2')

Does this help?

-Stefan


[1] http://docs.puppetlabs.com/guides/custom_functions.html
[2] https://github.com/puppetlabs/puppetlabs-stdlib
[3] http://docs.puppetlabs.com/references/2.7.9/function.html#regsubst

-Stefan

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to