Re: Petal problem

Bruno Postle <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.petal
Message-ID <[email protected]>
On Mon 07-Feb-2005 at 09:32 +0100, Christoph Thielecke wrote:
>
> If the "${1}" is in the text the parser fails.

Right, I've confirmed this.

Any Petal template with "${1}" in it fails because 
Petal::Hash::String thinks it looks like a variable but 
Petal::Hash::Var disagrees.

It is valid XML, but anything with '$' in it is going to be 
problematic because Petal uses it for variable substitution.

The following items all survive the Petal Parser untouched:

  <a>$</a>
  <b>$$</b>
  <c>$_</c>
  <f>$@</f>
  <g>$1</g>

..these are interpreted to nothing if they are undefined:

  <d>$foo</d>
  <e>${foo}</e>

..and these fail inelegantly:

  <h>${1}</h>
  <i>${1 bar}</i>
  <j>${1bar}</j>
  <k>${1_bar}</k>
  <l>${foo bar}</l>

The attached patch makes your particular problem go away, but I 
wonder if Petal should have a method of escaping '$' in a template.

Perhaps '$$foo' should be interpreted as the string '$foo' rather that 
a '$' followed by the variable '$foo'?

-- 
Bruno
Petal_dollar_one.patch (text/plain, 357 B)
Index: lib/Petal/Hash/String.pm
===================================================================
RCS file: /var/spool/cvs/Petal/lib/Petal/Hash/String.pm,v
retrieving revision 1.10
diff -r1.10 String.pm
15c15
< our $VARIABLE_RE_BRACKETS = qq |\\\$(?<!\\\\)\\{.*?(?<!\\\\)\\}|;
---
> our $VARIABLE_RE_BRACKETS = qq |\\\$(?<!\\\\)\\{[^0-9].*?(?<!\\\\)\\}|;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.