[Petal] Petal::Teng 0.03

Fergal Daly fergal at esatclear.ie
Fri Jun 13 17:27:54 BST 2003


http://www.fergaldaly.com/computer/Text/

A slightly updated version. Especially for Steve Purkis, this one allows

petal:define="thing/this/that[5] bob/bib/bub"

which will be translated into roughly

$hash->{thing}->this/that->[5] = $hash->{bob}->bib->bub

The only restriction is that you must you the array or hash hinting syntax for 
the last part of the path. So

define="this/that thing/other"

will give an error. This is because at compile time it's impossible to know if 
the last part of the path is a method name or a hash key or array index.

The hinting syntax works like this: instead of using / in the path you use {} 
or [], just like Perl. 

this{key} is $hash->{this}->{key}, never $hash->{this}->{key}
this[5] is $hash->{this}->[5], never $hash->{this}->{5}
this/method() is $hash->method(), never $hash->{this}->{method}

There are several reasons for this.

* if you are setting a variable, I think it's fair to expect you to know if 
it's a hash or an array
* there's no way to know what this/2 means - is this an array or a hash?

Actually, it would be possible to make this all work without {}s and []s by 
using lvalue subroutines and lots of extra work but I'm quite dubious about 
the whole idea of allowing this sort of define at all so I'm not going to 
implement that!

F



More information about the Petal mailing list