Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Extending Perl::PIE - how to have Perl snippets executed ?

by spazm (Monk)
on Jul 08, 2009 at 21:14 UTC ( [id://778415]=note: print w/replies, xml ) Need Help??


in reply to Extending Perl::PIE - how to have Perl snippets executed ?

what is Perl::PIE? Can you provide a link, I can't find any details.

Please also include the code you've written or tried thus far.

thanks

Replies are listed 'Best First'.
Re^2: Extending Perl::PIE - how to have Perl snippets executed ?
by Anonymous Monk on Jul 08, 2009 at 22:30 UTC
    Hi,

    I guess it would be too much to include code. You can find Perl::Pie here :
    http://www.pre-emptive.net/doco/pie-perl-inference-engine

    The problem is that I do eval from Perl::PIE package extensions and it doesn't work, while it works in main program when used directly without eval...

    Small Example:
    main program:
    ... use Pie::KnowledgeBase; use Pie::Engine; use Pie::KnowledgeBase::Dumper; use Data::Dumper; require 'time_utilities.pl'; # For misc. functions (e.g. time/da +te stamp routines) use Time::HiRes('gettimeofday'); use vars qw($Time $Second $Minute $Hour $Mday $Wday $Day $Month $Year) +; ...


    then I have somewhere in Perl::PIE packages snippet:
    ... print " ----------------- " . $ref->{attribute} . "\n" +; ...


    where $ref->{attribute} includes string to print that is defined in xml config :
    <rule name="print status every 5 secs"> <condition attribute='main::new_second(5)' type="time" trigger="1"> +1</condition> <action attribute="\n****************print status every 5 secs: New +_Second: Weekday:$Wday Time:$Hour:$Minute:$Second Time_Now:$Time_Now +Date:$Mday/$Month/$Year" type="print">1</action> </rule>

    and I don't get variables substituted in printed text by their value, so I get exactly literally the same string back :
    "\n****************print status every 5 secs: New_Second: Weekday:$Wday Time:$Hour:$Minute:$Second Time_Now:$Time_Now Date:$Mday/$Month/$Year"

    What should I do to print real values of variables and not literally their names ?

    Thanks in advance,

    Rob.

      Rob,

      Thanks for the update. I don't have time to look at it currently, but a perl rules engine sounds interesting.

      It looks like you need something to interpolate your string. So, something like changing your print routine to include an eval of the string?

      I don't think the code below works, but may prove helpful? You may also find yourself doing a search on the returned string to fill in values... blech.

      $string =~ s/\$(\w+)/ ${$1} /xeg;
      orig:
      print " ----------------- " . $ref->{attribute} . "\n"
      new:
      my $string = $ref->{attribute}; my $output = eval $string; if($@){ die "problem with eval: $@"; } print " ----------------- $output\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://778415]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-03-19 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found