>>>>> "AA" == Alex Aminoff <[email protected]> writes:

  AA> On Tue, 25 May 2010, Uri Guttman wrote:

  >> so that is 6 ways to do it without eval and tied. :)

  AA> Thanks, I did in fact consider, and in a couple cases implement, all
  AA> of those possible solutions, but was not happy with any of them.

  AA> Basically, either the template is too cluttered:

  AA>  <a href="[%url%]">[%title%]</a>...

  AA> or I am using regexp replacement. I suppose I trust perl's parser and
  AA> variable interpolation more than my own, which is why I like eval.

you should NOT like eval. it is very dangerous and overkill for
this. eval should be a last resort when no other reasonable solution can
be found. it is not a basic tool but only meant for advanced things
because of its danger.

  AA> I won't know the names of the methods until run-time since I am
  AA> building a general purpose utility that can be used with any object.

so? you need to deal with that issue regardless of interpolation as i
pointed out before. 

  AA> If we don't like eval I might be able to use String::Interpolate
  AA> instead, though honestly I have read their documentation 3 times now
  AA> and still don't precisely understand it.

  AA> Broadly, what I want to do is almost what is described here:

  AA>  http://dev.perl.org/perl6/rfc/222.html

  AA> except that I have one object on which all the methods will be called,
  AA> so no need to repeat the object many times.

repeat the object? show some example code of what you mean.

  AA> Possibly that means I can "use v6" and get what I want, although I
  AA> have not read up on what else that would change
  AA> backwards-incompatibly.

it means you are dependent on v6 modules. not a killer if you don't need
to worry about older perls.

  AA> So it sounds like the best practice would be to go back to my own
  AA> regexp substitution. Hm. Is there perhaps a packaged regexp somewhere
  AA> that finds and replaces exactly the same strings of the form $abcd
  AA> that the perl parser would?

again, one of my solutions is fine. try the hash one and straight
interpolation. you can code up a loop to make many method calls and
store the results in the hash. then the string is easy to create and
interpolate.  or even use a bunch of scalars if there aren't too many.

you haven't shown enough user code or requirements to help us make a
best practice selection.

uri

-- 
Uri Guttman  ------  [email protected]  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to