Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Seekers of Perl Wisdom

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

If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this section is the place to ask.

However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.

Post a new question!

User Questions
Current State of Financial Data Available to Perl
3 direct replies — Read more / Contribute
by justin423
on Sep 25, 2022 at 14:35
    I am trying to build a program that downloads the data on options on a handful of securities once a day after the market closes. There are a number of sites that provide an API for Python, but I am not seeing the same for Perl. the modules that would do this look very out of date (like Finance::QuoteOptions) It looks like yahoo and google removed their finance data download options. I know this is a longshot, but just thought I would ask here.
Can't make WWW::Mechanize work through proxy programmatically
2 direct replies — Read more / Contribute
by igoryonya
on Sep 24, 2022 at 01:46
    When I run the mechanize script from the shell with the /https?_proxy / set to the proxy server, it works through proxy, but when I run the script without that environment variable set in the shell and try to set the proxy internally in the program (script), it doesn't work.
    I tried setting:
    $ENV{'https_proxy'} = 'http://127.0.0.1:8118';
    or:
    $ENV{'HTTPS_PROXY'} = 'http://127.0.0.1:8118';
    prior to calling:
    $mech->get($url);
    Also, I tried the same, as above, but adding the following prior to ->get command:
    $mech->env_proxy;
    Also, instead of setting the $ENV{var} with ->env_proxy command, the following, prior to ->get:
    $mech->proxy(['https'],  'http://127.0.0.1:8118');
    or:
    $mech->proxy(['http'],  'http://127.0.0.1:8118');
    Also, tried to disable https, as was suggested on some forums:
    $mech->proxy(['http'], 'http://127.0.0.1:8118'); $mech->proxy(['https'], undef);

    but nothing worked. My goal is to be able to dynamically switch proxy for the same url, i.e. different proxies are set to work through different providers and there is also an internet on direct connection. I want to cycle between direct connection and different proxies, on fail, until getting success. My current code is:
    #!/usr/bin/env perl use WWW::Mechanize; my @https_proxy = ( 'http://127.0.0.1:8118' ); my $url = shift; #print "LWP::Protocol::https::VERSION: ($LWP::Protocol::https::VERSION +)\n"; $ENV{'https_proxy'} = $https_proxy[0]; my $mech = WWW::Mechanize->new(autocheck=>1); $mech->proxy(['http'], $https_proxy[0]); #$mech->proxy(['https'], undef); #$mech->env_proxy; $mech->get($url); print $mech->content;
Parsing bracket formatted file
7 direct replies — Read more / Contribute
by Stilgar
on Sep 23, 2022 at 19:13

    I have a bunch of files I need to pull into a data structure hash of hashes. The overall record is enclosed with brackets and is composed of KEY, VALUE pairs. The KEY is always text followed by a space, then the VALUE, which can be simple text or another bracketed sub-record. For example

    sys ecm cloud-provider /Common/aws-ec2 { description "The aws-ec2 parameters" property-template { account { } availability-zone { valid-values { a b c d } } instance-type { valid-values { t2.micro t2.small t2.medium } } region { valid-values { us-east-1 us-west-1 } } } }

    That's a simple one and there are arbitrarily nested records. It was originally formatted with newlines and spaces as well but that's been removed. So, for example, KEYS are usually separated by a newline, but sometimes just spaces. It's always some type of whitespace. I've been trying to parse it out with regex'es after slurping the file in a scalar, then tried writing a recursive function to do it. Any advice on the best way to approach it would be greatly appreciated!

Perl Tk crashes when mem usage exceeds 4G on Win10
3 direct replies — Read more / Contribute
by boleary
on Sep 23, 2022 at 06:48

    I have a Perl Tk GUI application that crashes after it exceeds 4GB of RAM usage and I have no issues exceeding 4GB when running tests in a console application (without Perl Tk)

    Operating system: Microsoft Windows Version 10.0.19044.2006 Perl version: v5.30.3 Tk version: 804.036 (latest available on CPAN)

    Perl spits out this error almost every time it crashes, but sometimes it crashes without an error:

    Free to wrong pool 678ea0 not e228dd0 at .\common\GUI_TESTS\test_memor +y_hog_gui.pl line 41.

    When searching for this error, everything I could find was multi-threading related, and our application does not use multi-threading. I thought it may be because we have something configured as 32-bit instead of 64-bit, so I followed the instructions in this question and found that everything is configured as 64-bit.

    perl -V:ivsize # ivsize='8'; perl -V:ptrsize # ptrsize='8'; perl -V:archname # archname='MSWin32-x64-multi-thread';

    Below is an example GUI application that crashes after the memory exceeds 4GB. I have boiled this down from our application and the crashing behavior is the same. The data structure that we use is obviously much larger, so I am cloning a simplified version of ours many times to pass the 4GB threshold.

    Note that this sample application does not crash when running on a Centos7 VM (only on the Win10 host)

    use strict; use warnings; use Tk; use Tk::LabFrame; use Clone; my $MAIN_WINDOW = MainWindow->new; $MAIN_WINDOW->minsize(400, 400); my @dataStructureClones = (); my $textBox; my $button_frame = $MAIN_WINDOW->LabFrame(-label => "Test", -relief => + 'groove', -borderwidth => 2)->pack(); $button_frame->Button( -text => 'Run Crashing Operation', -command => sub { my $dataStructureThatCrashes = { NETLIST_INFO => { EXTRA_PROPERTIES => { C_SIGNAL => {}, NET => {}, }, NET_LIST => [ # omitting this call will allow the program to exc +eed 4GB until after it finishes the loop { NL_INDEX => 0, } ] }, }; my $lastUpdate = time(); push @dataStructureClones, $dataStructureThatCrashes; for (1 .. 5000000) { if (time() - $lastUpdate > 1) { # omitting this call will allow the program to exceed +4GB $textBox->insert("end", "Cloning hash ($_)...\n"); $MAIN_WINDOW->update(); $lastUpdate = time(); } push @dataStructureClones, Clone::clone($dataStructureThat +Crashes); } } )->grid(-row => 0, -column => 0); $textBox = $MAIN_WINDOW->Scrolled( 'Text', -relief => 'groove', -background => 'light grey', -foreground => 'black', -wrap => 'char', -scrollbars => 'osoe', -width => 110, -height => 24, )->pack(-side => 'top', -fill => 'both', -expand => 1); MainLoop;
How to tell EU::MM to install a pure-perl module into an architecture-specific location
3 direct replies — Read more / Contribute
by syphilis
on Sep 23, 2022 at 01:08
    Hi,

    I have an "architectured" perl installation where, in addition to perl/site/lib, I also have:
    perl/site/lib/MSWin32-x64-multi-thread perl/site/lib/MSWin32-x64-multi-thread-ld perl/site/lib/MSWin32-x64-multi-thread-quadmath perl/site/lib/MSWin32-x86-multi-thread perl/site/lib/MSWin32-x86-multi-thread-64int perl/site/lib/MSWin32-x86-multi-thread-64int-ld perl/site/lib/MSWin32-x86-multi-thread-64int-quadmath perl/site/lib/MSWin32-x86-multi-thread-ld perl/site/lib/MSWin32-x86-multi-thread-quadmath
    Pure-perl modules will, by default, be installed into perl/site/lib.
    Other modules (ie perl extensions) will be installed into the appropriate location listed above, according to the perl architecture for which they have been built.

    I have a perl extension called (say) Module::B, and it has been built and installed into each of those architecture-specific locations.
    There also exists a pure-perl Module::A, which requires Module::B but has not yet been installed anywhere into that perl.

    Using (say) the MSWin32-x64-multi-thread build of perl, I then install Module::A in the usual way (cpan -i Module::A).
    Module::A gets installed into perl/site/lib because it is a pure-perl module.
    At that point, Module::A becomes immediately available to all 9 architectures, even though it has not been tested against 8 of them.

    This is an unsatisfactory state of affairs, IMO.
    I envisage that Module::A should really be installed into the relevant architecture-specific location.
    How do I tell ExtUtils::MakeMaker to do that ?
    Or is there some better way of handling this ?
    How do module authors generally deal with this issue ?

    Cheers,
    Rob
I cannot execute a url request through Dancer
1 direct reply — Read more / Contribute
by logangha
on Sep 22, 2022 at 19:56

    Hi there
    I am trying to make a request to a Dancer application which is initialized as I indicate:
    # perl serv.pl
    >> Dancer 1.3513 server 9802 listening on http://xxx.xx.xx.xx:xx
    >> Dancer::Plugin::REST (0.11)
    == Entering the development dance floor ...

    But when I tried to execute below command
    curl http://ipaddress:port/reference/C00-1412-0010

    It shows this result:
    curl http://ipaddress:port/reference/C00-1412-0010

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Error 500</title> <link rel="stylesheet" href="/css/style.css" /> <meta http-equiv="Content-type" content="text/html; charset=UTF-8" /> </head> <body> <h1>Error 500</h1> <div id="content"> <h2>Unable to process your query</h2>The page you requested is not ava +ilable </div> <div id="footer"> Powered by <a href="http://perldancer.org/">Dancer</a> 1.3513 </div> </body> </html>#

    This is part of the code
    package MyWebService; use strict; use warnings; use Dancer; use Dancer::Plugin::REST; use Config::File::Simple; use File::Slurp; use URI::Encode qw(uri_encode uri_decode); use IO::Socket; use IO::Select; use Storable; use Tie::IxHash; use REST::Client; use MIME::Base64; set server => 'xxx.xx.xx.xx'; get '/reference/:reference' => sub { writeLog("Arrived reference: " . params->{reference}); my (@arrRes, @arrNoRes) = processRequest(params->{reference}); if (@arrNoRes > 0) { push(@arrRes, @arrNoRes); } my $jsonResponse; if (@arrRes == 0) { $jsonResponse = to_json { reference => params->{reference} } +; } else { writeLog("Found results: " . Dumper(\@arrRes)); $jsonResponse = encode_json(\@arrRes); } return $jsonResponse; }; dance; . . .
    Below are all the functions called for this code.
    What is missing to allow this code works when it is invoked as a url with curl command?

Perl::Critic policy to catch quoted execution?
4 direct replies — Read more / Contribute
by Your Mother
on Sep 22, 2022 at 12:17

    Is there a Perl::Critic policy to catch attempts to use method calls within interpolation? So, it would catch this, and perhaps more convoluted examples like "$ref->()" or "$obj->$meth".

    say "U GOTS $account->balance LEFTZ";

    If not, would you do it naÔvely in PPI or something? This isnít a big enough deal to chase a lot, Iím just curious. :P

Recursive subroutines and closures
5 direct replies — Read more / Contribute
by ibm1620
on Sep 20, 2022 at 19:38
    When I write a recursive subroutine, I usually have to write two subroutines: A(), which sets things up properly and then calls B(), which is the actual recursive subroutine and is not intended to be called by anyone except itself and A().

    I wrote a simple routine make_backup($file) to make a backup of a file by copying it to $file.bak, first renaming any previous backups by appending another ".bak". In doing so I accidentally located the recursive subroutine inside the first subroutine (which I didn't know was possible).

    use v5.36; use File::Copy; # Copy $path to $path.bak, preserving all earlier backups sub make_backup ($path ) { my $path_bak; if (-e $path) { $path_bak = _preserve_previous_backup($path); copy $path_bak, $path; } return $path_bak; # undef if path didn't exist sub _preserve_previous_backup ( $path ) { my $path_bak = "${path}.bak"; if (-e $path_bak) { _preserve_previous_backup($path_bak ); } move $path, $path_bak; return $path_bak; } }
    And it worked. I thought this was a nifty way to encapsulate the "non-public" subroutine, until I realized what I'd done was to create a closure, which I'm unfamiliar with at this point.

    I do like the idea of nesting the recursive piece inside the outer sub in this manner, and it does appear to work properly, but from what I've learned so far, this is not what "closures" are meant for. Could I get some enlightened commentary on the most-likely-unwise thing I'm doing?

Parallel processing on Windows
4 direct replies — Read more / Contribute
by BernieC
on Sep 20, 2022 at 14:13
    I have a program that can reasonably easily set up to "parallel process". Back in my Unix days this was easy to do. I've looked at Perlfork and it says
    On some platforms such as Windows where the fork() system call is not available, Perl can be built to emulate fork() at the interpreter level. While the emulation is designed to be as compatible as possible with the real fork() at the level of the Perl program, there are certain important differences that stem from the fact that all the pseudo child "processes" created this way live in the same real process as far as the operating system is concerned.
    and I don't know what it means to have 'pseudo child "processes" created this way live in the same real process as far as the operating system is concerned'. I'm using Strawberry perl on win10. My hope is to be able to get my compute-bound Perl program to use more of the several "cores" in my cpu. Has anyone tried this? Does it work?
How to convert a vague time specfier into a concrete timestamp
6 direct replies — Read more / Contribute
by chrestomanci
on Sep 20, 2022 at 12:00

    Greetings wise brothers,

    I am looking for ways to do what the user means, even when they are annoyingly vague about it.

    Specifically I am looking to write a user friendly program that will accept a vague time specifications such as "now", "today", "5pm Friday" etc from a user and convert it into a timestamp, similar to how the unix at job scheduler does it.

    This will be for an interactive program, so the date parser does not need to be perfect, but it would be nice if I could find a library that is contains more parsing logic than I will have time to write myself.

    Any links? My google fu is failing me, mainly because I can't work out what search terms to use.

    I found the at daemon source code, but the parser uses a ycc grammar that looks to tricky to port to perl in an afternoon!

    Thanks.


Add your question
Title:
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":


  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2022-09-27 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (119 votes). Check out past polls.

    Notices?