# Change replace character in string and add strings?

I have a software to deploy where the installer for version 5.3.7 has 537 in its name (which is a parameter to the class). Its full name will be something like mysoftware-537-linux-ia32.bin or mysoftware-537-linux-x86_64.bin depending on the architecture.

I have this in my class:

softprefix = "mysoftware-"
version = "5\_3\_7"
softsuffix = "-linux-x86_64.bin"    # or  -linux-ia32.bin depending on the OS


How do I replace the "_" with "." in the string 5_3_7 and make the version 5.3.7?

Also how do I concatenate the strings? installer = $softprefix+$version+$softsufix doesn't seem to work. edit retag close merge delete ## 1 Answer Sort by » oldest newest most voted For the string replacement, try regsubst: $softprefix = 'mysoftware-'
$version = '5_3_7'$softsuffix = '-linux-x86_64.bin'

$dottedversion = regsubst($version, '_', '.', 'G')


The 'G' says to replace globally across the string, not just the first match. (And remember that variable names in Puppet start with a '$' sign :) Concatenating strings is done inside double quotes, like this: $installer = "${softprefix}${version}${softsuffix}"  more ## Comments Thanks John. This works great with one change regsubst($version,'\.', '_', 'G') GLN

( 2014-09-30 09:50:37 -0500 )edit