Adventures in Perl: perl from php
Posted by: badanov
I recently worked up a perl script to compare two data objects to extract the difference between the two.
The perl module DateTime I use in many scripts here and in the wargame club. The module is very useful but it has problems with data display, and with date math. It is useful for extracting strings from unix dates and from created ( future ) dates.
I wound up. however, failing to resolve coding problems in dates math and was thus forced to program a mini-module to do the math for me. I just wants to display the days, hours minutes and second until an event at 00:01 every Friday.
The script is being used now but it isn't tested and will probably fail for times that span between months, and when it does I will resolve that problem.
But I want the script to dump the summary onto a php script and for that I have pecl-perl which is an extension which allows a php script to run a perl script and gain any resulting data returns back into the php script.
The demo/man page was simple enough but the problem was that the demo only showed how to dump the data type and the data when all I really wanted was just the data.
Seriously, if you know your perl scrpt is going to dump out a series of integers, who cares if the data type get dumped with it? It's just cruft that has to be removed from the resulting data.
Here was my solution:
$perl = new Perl();
$diffday = strval($perl->diffday);
$diffhour = strval($perl->diffhour);
$diffmin = strval($perl->diffmin);
$diffsec = strval($perl->diffsec);
Now the variables listed can be used on a php script. See the difference between this and the pecl-perl man page.
If you have something to add, Fire Away!
Number of Comments so far: 0
Click here for a list of stories in the Unix and Computer category