Re: [Puppet Users] regsubst questions

2010-04-23 Thread Thomas Bellman

On 04/23/10 15:55, ed-rfmd wrote:


 $boot_time = generate('/usr/bin/env', '/bin/date', '+%H:%m')
 notice("boot_time =>  $boot_time")
 $boot_hour = regsubst($boot_time,'^([0-9]+)[:]([0-9]+)\n','\1')
 notice("w newline - boot_hour =>  |$boot_hour|")
 $boot_hour_1 = regsubst($boot_time,'^([0-9]+)[:]([0-9]+)','\1')
 notice("w/o newline - boot_hour_1 =>  |$boot_hour_1|")

And the lines from the messages file:

   (Scope(Class[main])) boot_time =>  09:04
   (Scope(Class[main])) w newline - boot_hour =>  |09|
   (Scope(Class[main])) w/o newline - boot_hour_1 =>  |09 |

  What I don't understand is that in the first setting of the variable
the trailing new line is specified in the regsubst pattern but is not
included in the resulting variable. In the second case, the new line
is not specified but is part of the resulting variable. In neither
case is the new line in the capture group. I would think that the
capture would include only the characters specified in the group, i.e.
one or more digits before a colon.


The return value from regsubst() is not just the matching part of the
original string, but the *entire* original string with the substition
performed.  For example, regsubst("bananas", "(n)", "!", "G") will
return "ba!a!as", even though neither "ba" nor "as" matches "(n)".

*Since* the newline in your example isn't matched by the second
regexp, it will not be replaced, and thus be left alone and be part
of the return value.


/Bellman

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



[Puppet Users] regsubst questions

2010-04-23 Thread ed-rfmd
I am attempting to set some variables in my manifest and I amd seeing
a result I don't quite understand. Here is a section of code from my
manifest:

$boot_time = generate('/usr/bin/env', '/bin/date', '+%H:%m')
notice("boot_time => $boot_time")

$boot_hour = regsubst($boot_time,'^([0-9]+)[:]([0-9]+)\n','\1')
notice("w newline - boot_hour => |$boot_hour|")

$boot_hour_1 = regsubst($boot_time,'^([0-9]+)[:]([0-9]+)','\1')
notice("w/o newline - boot_hour_1 => |$boot_hour_1|")

And the lines from the messages file:

  (Scope(Class[main])) boot_time => 09:04
  (Scope(Class[main])) w newline - boot_hour => |09|
  (Scope(Class[main])) w/o newline - boot_hour_1 => |09 |

 What I don't understand is that in the first setting of the variable
the trailing new line is specified in the regsubst pattern but is not
included in the resulting variable. In the second case, the new line
is not specified but is part of the resulting variable. In neither
case is the new line in the capture group. I would think that the
capture would include only the characters specified in the group, i.e.
one or more digits before a colon.

 Can anyone explain this behavior.

Thanks,
Ed

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