WolframAlpha API: how to specify multiple pods? - perl

Currently I am specifying multiple pods in the following way:
my $q = $wa->query(
'input' => $input,
'format' => 'plaintext',
'includepodid' => ['Input', 'Result', 'WeatherForecast:WeatherData', 'ForecastCharts:WeatherData'],
'reinterpret' => 'true',
);
However it then returns empty result – number of pods is undefined, so as are other fields. Setting only a single pod id with:
'includepodid' => 'Result'
does work so the code is overall correct. Using [ 'Result' ] yields the same incorrect behavior.

It's maybe a little late for you but for anyone else experiencing this: You mustn't set the includepodid parameter with delimiters you have to set it multiple times meaning instead of this:
...&includepodid=ID1,ID2
do this:
...&includepodid=ID1&includepodid=ID2
Worked for me though..

Related

Get Values out of Complex Perl Hash Structures

With the following Code I can fetch Data stored in a Hash from a Database and print it out:
use Data::Dumper;
my $fdx = $s->field(); # get Hashreference from Database
print Dumper($fdx); # print out Hash
The (important part of the) Output looks like this:
$VAR1 = bless( {
'selectable' => 'true',
'_PARENT_OBJECT' => bless( {
'dirtyFlag' => 1,
'path' => undef,
'testItems' => [],
'data' => {
'TEST_10' => {
'atm_rundatahistory' => {
'1523964918' => {
'atm_prid' => {
'content' => '',
'label' => 'Problem Report IDs',
'raw' => ''
}, ...
'1523964410' => {
'atm_prid' => {
'label' => 'Problem Report IDs',
'raw' => '23361234',
'content' => '23361234'
}, ...
'Test_10' is one of hundreds of Tests, '1523964918' is one of many unix timestamps, so basically its a 32 Bit Integer, but I dont know which numbers the timestamps contain.
How do I print out / access the values for 'content' (in this case '23361234') of the most inner Hashes, for all Tests and unix timestamps, if they exist?
from here on I will describe my thoughts and what I have tried, its not necessary to read any further for this question.
I think the code I am looking for is something like:
foreach my $val($fdx{_PARENT_OBJECT}{data}{"TEST_*"}{atm_rundatahistory}{"********"}{atm_prid}{content})
print("\n$val");
However I don't know the exact Syntax, and neither do I know which placeholders to set for "Test_10", since there are many tests numbers, e.g. "...Test_132...Test_134" and the Unix timestamps can be any 32 Bit Integer, so I guess I can use start as a placeholder? e.g. "********".
After some hours of searching on the web, I haven't found a understandable tutorial on how to access values from complex Perl hash structures, I guess there are some simple syntax-rules to know and you can get any value of even very complex data structures without to much effort.
I've already read perldoc_perlreftut. If there is any other easy to understandable tutorial for these kind of problems, please recommend them to me. I don't really know how I can learn to handle such complex data structures in Perl myself.

phpseclib createKey() using own primes

Is it possible to generate private and public key in PKCS#1 format using phpseclib and my own primes? I mean I already have p and q and I want to generate both keys. I am trying to do something like this:
$p = new Math_BigInteger(...);
$q = new Math_BigInteger(...);
$custom_primes = serialize(array('primes'=>array(1=>$p,2=>$q)));
extract($rsa->createKey(512,10,$custom_primes));
But this gives me the fatal error:
Fatal error: Call to a member function divide() on a non-object in /volume1/web/phpseclib/Crypt/RSA.php on line 705
I checked this and it is trying to divide:
list($temp) = $lcm['top']->divide($lcm['bottom']);
Obviously I am not setting up lcm in my $custom_primes structure as I only have my two primes. So the question is: is it possible at all in phpseclib?
It looks like you're trying to use phpseclib's partial key functionality to achieve this. Problem is that expects more than just primes. See this, for example:
return array(
'privatekey' => '',
'publickey' => '',
'partialkey' => serialize(array(
'primes' => $primes,
'coefficients' => $coefficients,
'lcm' => $lcm,
'exponents' => $exponents
))
);
$lcm is defined, initially, like this:
$lcm = array(
'top' => $this->one->copy(),
'bottom' => false
);
So maybe try doing that as well. You can probably strip out all of the calculation functions
from phpseclib, do them yourself and then pass $partial into phpseclib and let it generate a key in whatever format you want it generated in.

MongoDB (via Fuelphp): Adding entries on an Array

I would appreciate the help here. For the purpose of this discussion I have an example here (I will use paste bin for the codes):
http://pastebin.com/VPuyKn6W
I am trying to produce this output:
http://pastebin.com/4iMLacRu
I understand that I need to use $push to make this work. But upon testing, it doesn't seem to do anything. I am following the instructions as prescribed in the docs, but instead of using $Id, I am using user_id for finding the document in the collection. Here is my model:
http://pastebin.com/QB94tbZn
Am I misunderstanding something, or I am not using the $push operator properly, or something to do on how I created the document?
After walking outside, I finally got my answer.
public static function create_mongo()
{
$data = array(
'user_id' => '123895',
'First_Name' => 'John',
'Last_name' => 'Doe',
'sites' => array(
array(
'title' => 'Sankaku Complex',
'site' => 'http://sankakucomples.com'
)
)
);
$db = Fuel\Core\Mongo_Db::instance();
$db->insert('test_collection',$data);
}
sites should be an array carrying an array variable.

How can I get attributes from complex SOAP::DATA structure in SOAP::Lite?

I can't get a simple attribute value from SOAP response using SOAP::Lite.
Below the code and output of SOAP::Data. I'm trying to get value of the attribute //response/dirn/attr/uuid
my $cm = new SOAP::Lite
uri => 'http://www.cisco.com/AXL/API/1.0',
proxy => "https://10.0.0.1:8443/axl/";
my $res = $cm->getPhone(
SOAP::Data->name(phoneName => 'SEP00270D3D7A4C'),
);
for my $i ($res->valueof('//device/lines/line')) {
print Dumper($i);
#print $i->{dirn}->{attr}->{'uuid'}."\n"; # line below give me an error
}
Here the output of Data::Dumper. I actually have the requested value, but I can't get it through SOAP::Data
$VAR1 = \bless( {
'_signature' => [],
'_value' => [
bless( {
'_name' => 'dirn',
'_signature' => [],
'_value' => [
''
],
'_prefix' => '',
'_attr' => {
'uuid' => '{615C3550-1EFD-56C7-3788-2AA8725880E3}' #!!!!!!!!!!!!!!!!!!!!!!!!!!
}
}, 'SOAP::Data' ),
],
'_attr' => {}
}, 'SOAP::Data' );
I spent about several hours trying to get this attribute value. I've already thinking about using output of Data::Dumper to get the value as fast and dirty hack.
Thanks in advance
P.S.: SOAP Server is Cisco CUCM 6.1.5
$$i->value->attr->{uuid}
$i->{'_value'}[0]{'uuid'}
I think, though, I'm not sure about the [0].
I have same issue, but can not find an "quick and easy" solution to it. I developed a Perl library module to use certain vendor Web Service (WSDL). I had done many of such Web Service interfaces, but until now - all of the data was returned as XML "elements". On the contrary, this particular Web Service returns most of the data as XML elements, but also sets some - as XML attributes. I can not get values returned as attributes - since SOAP::Data methods (valueof(), body(), etc.) only return values of XML elements, but not associated attributes.
This problem is a little different from the one posted before - in that I do not know up front the XML structure that is being returned (given web service provides many different methods, and each - has different response).
So question is - how it is possible to get all of the XML data (both elements and attributes) for a generic response SOAP data
I went through the same thing recently and found the answer, refer to my question and my updated answer in the comments section.
Extract specific XML element in CDATA taken from SOAP::Lite Response Hash

How do I set up my POE::Filter to receive the entire chunk of data returned from the server?

I tried the following
my $filter = POE::Filter::Line->new(OutputLiteral => '');
my $wheel = POE::Wheel::ReadWrite->new(
Handle => $socket,
Filter => $filter,
InputEvent => 'on_input',
ErrorEvent => 'on_error',
FlushedEvent => 'on_flush',
);
But on_input is called several times with each line separately in ARG0. How do I get it all together? Doesn't setting setting OutputLiteral to '' change the filter's understanding of what a "line" is?
First of all, you are reading from the filter, so it's InputLiteral which is important here, not OutputLiteral. Second, you can't have an empty InputLiteral (if you try, it will just autodetect the input literal). Consequently, you can't use POE::Filter::Line to get all the data, because it is made for parsing line-terminated records. Use POE::Filter::Stream instead.