Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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
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
Tk design user interface
2 direct replies — Read more / Contribute
by Anonymous Monk
on Jan 23, 2020 at 07:10

    Hi, I am writing a script that searches for a file and reports about it, but i am having problems designing the user interface. I am using Tk and the pack function for this. Here is the code i have so far:

    use strict; use warnings; use Tk; my $mw = new MainWindow; $mw->geometry("400x400"); my $text = $mw->Text(-width=>15,-height=>3)->pack(-side=>'bottom',-anc +hor=>'w',-padx=>20,-pady=>10); my $label = $mw->Label(-text=>"File?",-anchor=>'w')->pack(-side=>'left +',-anchor=>'n',-padx=>20,-pady,10); my $entry = $mw->Entry->pack(-side=>'left',-anchor=>'n',-padx=>20,-pad +y=>10); my $button = $mw->Button(-text => "search!",-width=>30)->pack(-side => + 'left',-anchor=>'n',-padx=>20,-pady=>10); MainLoop;

    As you can see the textarea is located all the way to the bottom while i want it just below the other widgets. So all i need is to loose some vertical space but i am unable to do this. Sorry for my poor engish, please advice.

cpanm --installdeps . cannot install Template::Toolkit
4 direct replies — Read more / Contribute
by Skeeve
on Jan 23, 2020 at 03:29

    When building my Docker image I need to install Template::Toolkit using cpanm.

    In my cpanfile I've defined

    requires "Template::Toolkit","3.006";
    which clearly is the version I can find on cpan.org.

    But the build fails with

    ==> Found dependencies: Template::Toolkit ! Installing the dependencies failed: Module 'Template::Toolkit' is no +t installed ! Bailing out the installation for .. Found Template::Toolkit which doesn't satisfy 3.006.
    It only seems to be possible to be installed when defining the minimal version to be "0".

    What can I do about it? Can I do something about it?


    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Automating a Win10 GUI
3 direct replies — Read more / Contribute
by Marshall
on Jan 23, 2020 at 02:05
    I want to automate some Windows GUI interactions.
    There appear to be quite a number of tools that claim that they can "do this".
    I suspect that the solution to my problem will be some existing tool that has the capability of accepting Perl code for decision making.

    I currently only have a single monitor.
    I launch a program, let's just call this program X. "X" is designed to stay in the background of the GUI.
    Then I launch program "Y". "Y" has a many windows.
    I move the individual windows of application "Y" around so that I see the most important parts of application "X".
    Application X essentially functions as the "wallpaper".
    Unfortunately, program "X" has a timeout "nag window" that I have to click on every 15-20 minutes or so.
    That "nag window" will be displayed on top of the program X application, but below the windows for application Y which means that it might not even be possible to see on the monitor.

    I have considered and I am implementing the most obvious solution:
    Buy a second monitor and run "X" and 'Y" on 2 different monitors.
    Unfortunately that will not solve my complete problem. Program "X" is a bit funky and actually I just want to keep it running, and not mess with it at all. The interactions can be more complex than I described above.

    To further complicate matters, it is highly desirable to only use Perl libraries available on ActiveState's latest release.

Eval/package question
4 direct replies — Read more / Contribute
by Ratazong
on Jan 21, 2020 at 05:13

    Dear Monks,

    I'm struggeling with packages and eval ... here is my short example:

    package items; use strict; use warnings; use Data::Dumper; use Exporter; my %items; 1; sub initItems { $items{1}{Name} = "Rusty Sword"; # fine $items{2}{Value} = 2; # fine eval ("$items{3}{Value} = 2;"); # ERROR: Use of uniniti +alized value in concatenation (.) or string at items.pm line 16. (th +is line) print( Data::Dumper->Dumpxs( [ \ %items ], [ qw{ *items } ] )); }
    When running it (calling items::initItems(); in my main program), I get the error mentioned above, and the output is:
    %items = ( '1' => { 'Name' => 'Rusty Sword' }, '3' => {}, '2' => { 'Value' => 2 } );
    What is wrong? Why does the eval somehow access my hash, but does not add the value? Is it something obvious and I'm just blind today?

    Thanks for help! Rata

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 chilling in the Monastery: (6)
As of 2020-01-27 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?