Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

The Monastery Gates

( #131=superdoc: print w/replies, xml ) Need Help??

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
svg line graphs
1 direct reply — Read more / Contribute
by BernieC
on Jan 27, 2020 at 16:03
    From what I can tell, svg::tt:graph::xy can only plot a single data set. Other than that it looks great :o). Is it possible to get it to do multiple datasets {each in a different color}?

    I was thinking of writing my own program to do that. Doesn't seem too hard, but a bit complicated. I can see the parameters: x-range, y-range, y-title, x-title, y hash marks, x hash marks. And with that superstructure I think it'd be relatively easy to just do SVG lines from data-point to data-point but lots of messy stuff. I hit metacpan guessing that someone had done that and tt:graph:xy seems to only handle one set of data.

    Am I crazy/reinventinganoldwheel to start doing something like this just using the SVG package? Is there an existing package that I missed that could handle that?

Perl FCGI Error: mod_fcgid: error reading data from FastCGI server
1 direct reply — Read more / Contribute
by knox
on Jan 27, 2020 at 15:40

    Hello Monks,

    Your wisdom once again is appreciated. I've been testing some FCGI scripts, I've managed to get CGI::Fast working, but I'd like to get FCGI working. Unfortunately, I haven't be able to find good working examples. I'd like to see an example of FCGI return $ENV vars, similar to the CGI::Fast used in the Apache example: https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html. The code posted below is just me trying to get something to work, it is giving an internal server error. I've posted this is from my error log:

    [Mon Jan 27 19:44:02.915926 2020] [fcgid:warn] [pid 20681] (104)Connec +tion reset by peer: [client xx.xxx.xxx.xxx:xxxxx] mod_fcgid: error re +ading data from FastCGI server [Mon Jan 27 19:44:02.915973 2020] [core:error] [pid 20681] [client xx. +xxx.xxx.xxx:xxxxx] End of script output before headers: test.fcgi <code> <code> #!/usr/bin/perl use FCGI; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use Encode; #use CGI::Fast; #the CGI:Fast example from https://httpd.apache.org/mod_fcgid/mod/mod_ +fcgid.html is working; my FCGI example is not. my $count = 0; my $request = FCGI::Request(); while($request->Accept() >= 0) { $body = "Content-type:text/html; charset=utf-8\r\n\r\n"; $body .= '<html><head><meta http-equiv="Content-Type" content="te +xt/html; charset=utf-8" /></head><body>'; $body .= '<h1>Woohoooo!</h1>': $body .= '</body></html>'; $body .= '</body></html>'; $body = encode_utf8($body); print $body; }

    Aside from that, I have a very basic question with FastCGI - as it keeps a persistent connection, whats the best way to temporarily test it? I am new to FastCGI, it is compelling, but I don't know the vernacular to describe it well (yet). Let me know if the above doesn't make sense. Secondly, is there a way to get more descriptive error messages than the ones that come out of apache.log?

    And yes! I will look into frameworks like Plack/Dancer - but before I do, I'd like to get grasp of how FCGI works before I put a layer on top of it.

Mail::Chimp3 Add Member
2 direct replies — Read more / Contribute
by JEWebDes
on Jan 27, 2020 at 13:47

    I'm far from being a true Perl monk, and here's proof. I've been trying to add a member to a MailChimp list, but keep getting a 400 Bad Request - 'This value should of type object' error. The thing is I don't know how to build the Perl object required. Here's what I've tried:

    my $mailchimp = Mail::Chimp3->new( api_key => 'mykey' ); my %merge_fields = ( 'FNAME' => 'My', 'LNAME' => 'Name', 'PHONE' => '760-720-0000' ); my $response = $mailchimp->add_member ( list_id => '49ef108521', email_address => 'test@jmydomain.com', status => 'subscribed', merge_fields => %merge_fields );

    Obviously I haven't built the merge_field Perl object correctly. How should it be coded?

    Thanks for the help!

Hash (not) returned by subroutine
2 direct replies — Read more / Contribute
by Anonymous Monk
on Jan 27, 2020 at 04:49
    Hello,
    I did not expect that $result in the code below is set, since it is not returned by the called subroutine. Why it happens?
    Thanks.

    $ cat test.pl use strict; use lib ('.'); use Test qw (get_data); use Data::Dumper; my $result = get_data(); print Dumper $result; $cat Test.pm package Test; use strict; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(); our @EXPORT_OK = qw( get_data ); #------------- sub get_data { my $data = {a=>'b'}; } 1; $ perl test.pl $VAR1 = { 'a' => 'b' };
Outputting JSON with sorted names/keys
5 direct replies — Read more / Contribute
by pryrt
on Jan 25, 2020 at 19:15

    I'm trying to create a simple JSON file. I wanted to try to get the names/keys output in a specific (non-alphanumeric) order (to make it easier on the human users of the JSON -- I know it's irrelevant to any automated parsers). Using the JSON module, I can get unsorted or alphanumerically sorted. Manually rolling it, I can get in whatever order I specify. Is there an option I'm not seeing in the JSON docs for altering the sort-order? or another module that has user-supplied sort order?

    (It's not overly important; this is mostly as a learning opportunity; my manual_ordered_json could have finished this one-off job for me already, but I was hoping to expand my toolbase knowledge.)

    Thanks

missing second of time
8 direct replies — Read more / Contribute
by Anonymous Monk
on Jan 25, 2020 at 04:47
    I was calculating orbital elements once per second with Perl and noticed a glitch that occasionally doubled one of the derivatives for a single second.

    I was using the core function "time" and noticed that the unixtime stamp would skip a second just before the event would occur.

    Then I tried to see more with Time::HiRes and saw that a second would be skipped when the decimal turned over.

    I ran these two lines of code concurrently in bash shells, and saw the strange results:

    
    perl -le 'while () { print time; sleep 1 }'
    
    1579941920
    1579941921
    1579941922
    1579941924 <- WTF?
    
    perl -MTime::HiRes=time -le 'while () { print time; sleep 1 }'
    
    1579941920.99577
    1579941921.99751
    1579941922.99824
    1579941924.00213 <- WTF!
    
    
    A third terminal running at the same time printed the missing second, but, it skipped one when it eventually turned over.
    1579941920.51386
    1579941921.51823
    1579941922.52046
    1579941923.52163 <- OK
    1579941924.52477
    
    The interval does not seem significant:
    1579941920.99577
    1.00174
    1579941921.99751
    1.00073
    1579941922.99824
    1.00389
    1579941924.00213 <- WTF!
    
    I tried a lot of things like disabling NTP and using usleep but it always skips and causes my program to flip out for a second. What is this sorcery? Thanx
How do I Pull data out of Array inside of Hash
3 direct replies — Read more / Contribute
by nachtmsk
on Jan 24, 2020 at 19:33
    Hi,

    I am trying to pull JSON data from an online source.

    I was able to get the data and store it into $datahash.

    I dereferenced that into %hashdata

    Then ran through the keys. Output below.

    The key named "value" is an array. I need to run through that data in that array and work with it. It is the first value in the data section I printed out below the code.

    My question is how can I get the data out of that ARRAY that is in the hash %hashdata.

    Thanks very much for any help.

    Mike
    use LWP::Simple 'get'; use Data::Dumper; use Mojo::JSON qw(decode_json encode_json); use constant URL => 'https://api.bridgedataoutput.com/api/v2/OData/tes +t/test?access_token=xxxxxxxxxxxxxx'; my $json = get URL or die "Unable to get JSON data"; my $datahash = decode_json $json; %hashdata = %$datahash; #print Dumper(%hashdata); #print $hashdata{'value'}; ## Array that holds the data foreach $key (keys %hashdata) { $value = $hashdata{$key}; print "Key $key Value $value\n\n\n"; }
    Data returned =============

    Key value Value ARRAY(0x5612912d40c8) ## NEED to get into this Array and get data out.

    Key @odata.context Value https://rets.io/api/v2/OData/test/

    Key @odata.count Value 10006

    Key @odata.nextLink Value https://rets.io/api/v2/OData/test/test?access_token=xxxxxxxxx

Cheapest way for multiple external commands
3 direct replies — Read more / Contribute
by pedrete
on Jan 24, 2020 at 14:10

    Hi Monks...

    i need to run many externals commands from my Perl script and capture both return-code and STDOUT. These commands must run under a shell...

    To my knowledge, Perl always does a fork and then waits for the child to run the command, am i right?

    Is there any way to prevent that "fork"? i am looking for the "cheapest way" in terms of CPU and Memory load...

    THX!!!

    Pedreter.
New File Not Working
5 direct replies — Read more / Contribute
by jalopez453
on Jan 24, 2020 at 12:30

    I have script to where I am looking to update a date format, but for some reason my new file is not being created and I cannot see what I am missing or what is wrong. If someone could point out what I have wrong it would be truly appreciated.

    use strict; open(INFILE, "PSR_Date.txt"); open(OUTFILE, ">PSR_OutputDate.txt"); while (<INFILE>) { $line = $_; $line =~ s/(\d{4})-(\d{2})-(\d{2})\s\d{2}:\d{2}:\d{2}/ +\2\/\3\/\1/g; print OUTFILE "$line"; } close INFILE; print "Done!\n"; chomp($pause = <STDIN>); _DATA_ OD44202,07/01/2015,08/19/2019,08/27/2019,1,07/01/2015,06/30/2019,2015- +06-20 00:00:00 OD44202,07/01/2015,08/19/2019,08/27/2019,1,07/01/2015,06/30/2019,2015- +06-20 00:00:00 OD44202,07/01/2015,08/19/2019,08/27/2019,1,07/01/2015,06/30/2019,2015- +06-20 00:00:00 OD44202,07/01/2015,08/19/2019,08/27/2019,1,07/01/2015,06/30/2019,2015- +06-20 00:00:00 _OUTPUT_ OD44202,07/01/2015,08/19/2019,08/27/2019,1,07/01/2015,06/30/2019,06/20 +/2015 OD44202,07/01/2015,08/19/2019,08/27/2019,1,07/01/2015,06/30/2019,06/20 +/2015 OD44202,07/01/2015,08/19/2019,08/27/2019,1,07/01/2015,06/30/2019,06/20 +/2015 OD44202,07/01/2015,08/19/2019,08/27/2019,1,07/01/2015,06/30/2019,06/20 +/2015
Caching files
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jan 24, 2020 at 08:45
    Hi,
    I have list of coordinates and a subroutine that tells me in which JSON file among many I must retreve some content for each coordinate pair.
    The values in the JSON files change periodically.
    Could you please provide me some indications on how to implement a caching of the JSON information in a hash (I saw there is File::Cache) and monitor the changes to the JSON files so that the hash is updated?
    Thank you!
Catalyst with DBIx::Class User Roles Error
No replies — Read more | Post response
by Boydle
on Jan 23, 2020 at 23:16

    Hi, I hope someone can help me with a problem I am having with the user and roles structure as defined in the catalyst tutorial. I am working on a new project using Catalyst, DBIx::Class and HTML::FormFu I am fairly new to these 3 modules.

    I have used the tables and I am now trying to use a FormFu form to allow me to create a new user and assign roles to them. I am getting the following error: Caught exception in Indium::Controller::Admin::User->create "The primary key and the foreign key may not be the same column in class Indium::Schema::Result::UserRole at .....

    I have tried adding a new id column to user_role and making it the primary key however this breaks the inbuilt $c->check_any_user_role('myrolename'); this does not error but returns false instead of true as expected and what was occurring before adding the id field as primary. Removing the primary also does not work.

    FormFu roles select:
    - type: Select label: Role multiple: 1 name: user_roles model_config: resultset: Role label_column: role id_column: id

    The user creation itself is working if I remove the roles from the form.

    This is the user role_model

    __PACKAGE__->table("user_role"); __PACKAGE__->add_columns( "user_id", { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, "role_id", { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, ); __PACKAGE__->set_primary_key("user_id", "role_id"); __PACKAGE__->belongs_to( "role", "Indium::Schema::Result::Role", { id => "role_id" }, { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" + }, ); __PACKAGE__->belongs_to( "user", "Indium::Schema::Result::User", { id => "user_id" }, { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" + }, ); __PACKAGE__->meta->make_immutable; 1;
Getting JSON data from a URL using LWP
1 direct reply — Read more / Contribute
by nachtmsk
on Jan 23, 2020 at 16:03
    Hi, I need to get JSON data from a URL. This is the URL, minus the actual Auth code at the end.

    https://api.bridgedataoutput.com/api/v2/OData/test/TestData?access_token=xxxxxxxxxxxxxxxxxxxxxx

    If I type this URL into my browser it brings back the data I need. However, if I use it in the code below I get the 'die' message I have set below. My main task right now is to just get the data from the URL into a perl variable. Later on I can worry about parsing the JSON. I have used LWP before to get data this way, usually XML. I can't figure out why this isn't working.

    Any help would be appreciated.

    ---------------------------
    use strict; use warnings 'all'; use LWP::Simple 'get'; use JSON::Parse 'parse_json'; use constant URL => 'https://api.bridgedataoutput.com/api/v2/OData/tes +t/TestData?access_token=xxxxxxxxxxxxxxxxxxxxxx'; my $json = get URL or die "Unable to get JSON data"; my $data = parse_json($json); print $data;
    Thanks! Mike
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2020-01-28 04:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?