Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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
Disabling runtime warnings in dynamic scope?
3 direct replies — Read more / Contribute
by LanX
on Apr 25, 2018 at 18:26
    On request of a colleague I was playing around with an own implementation of switch as replacement for given/when

    Surprisingly, I can use next within a sub to be able to fall thru to the next case, which leads to a nice syntax.

    use strict; use warnings; use diagnostics; sub switch { no warnings 'exiting'; while (@_) { my ($case, $action) = splice @_,0,2; return $action->($case) if $_ ~~ $case; } } #no warnings 'exiting'; switch [1,2,3] => sub { print "bla" ; next}, 3 => sub { print "bla2" } for (3);

    But I'm getting

    Exiting subroutine via next at d:/Users/RolfLangsdorf/pm/ lin +e 18 (#1) (W exiting) You are exiting a subroutine by unconventional means, +such as a goto, or a loop control statement.

    Obviously I can't dynamically disable the warning, because it's lexically scoped.

    Uncommenting the #no warnings 'exiting' works, but would be acting for a much wider scope.


    Is it possible to disable a certain warning in the dynamic scope?

    Overwriting the warn handler does the trick ...

    local $SIG{__WARN__} = sub { warn "$_[0]" unless $_[0] =~ /^Exiting subroutine via next/ } ;

    ... , but maybe there is a cleaner solution?

    NB: this is experimental code and not meant for production! :)

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Wikisyntax for the Monastery

XS/C, threads, and calling call_sv() with a code ref
2 direct replies — Read more / Contribute
by stevieb
on Apr 25, 2018 at 15:16

    Hello fellow Monks,

    I am experiencing an issue with some C/XS I'm trying to get working. I will explain what I'm trying to do, how I perceive what the code is actually doing and a bit about what's happening. I'll then show the Inline::C code, the output, some gdb debugging output. Unfortunately, unless you have a Raspberry Pi, there's no way you can repro this successfully.

    What I'm trying to do:

    I have an interrupt routine for a GPIO pin on the Pi. This interrupt routine (ISR) is spun off into a separate C++ thread, and to facilitate the ability for the user to use a Perl subroutine as the callback/interrupt handler, I'm trying to pass in a code reference, and have the C/XS execute that sent-in-as-a-param code ref.

    What is the code doing?:

    I set up a function in main called cref_handler(). I then initialize the RPi, configure the appropriate GPIO pin, then set the interrupt on that pin, passing in a reference to the mentioned cref_handler() routine. The interrupt handler (the code the coderef points to) is to run any time the specified pin goes LOW (ie. 0 volts). Both the interrupt setup and the actual interrupt handler that executes the code in the coderef is written in C and passed along to an external library that dumps the ISR into its own thread.

    What the hell is happening?:

    The callback code simply prints to STDOUT. Once the script is run, I may get a few printouts when shorting (ie. turning LOW the pin), sometimes I don't. In all cases, it eventually leads to a SEGFAULT. Sometimes after a microsecond, sometimes after a second or two.

    I'm not an expert C coder by any stretch, so I believe what may be happening is that the threaded interrupt code isn't handling the global C variables I've set up, or perhaps it's the way I'm using some of Perl's internals wrong (eg: PerlInterpreter, PERL_SET_CONTEXT etc), or the way the interruptHandlerCref() XS code is laid out.


    I'd greatly appreciate it if those experienced in these XS/C matters could have a look and see what I'm doing wrong here, if its possible without having to actually run the code (I truly apologize for that inability). I'm thinking it's my inexperience with C, or misunderstanding how the whole background threads thing is handled here.


    use warnings; use strict; use RPi::Const qw(:all); use Inline ('C' => 'DATA' => libs => '-lwiringPi -lrt -lwiringPiDev -l +pthread'); my $continue = 1; $SIG{INT} = sub { $continue = 0; }; sub cref_handler { print "cref handler\n"; } my $cref = \&cref_handler; init(); pin_mode(3, INPUT); setInterruptCref(3, EDGE_FALLING, $cref); my $running; while ($continue){ print "running\n" if ! $running; $running = 1; } __DATA__ __C__ #include <wiringPi.h> #include <stdio.h> void init (){ wiringPiSetupGpio(); } PerlInterpreter* mine; SV* perl_callback_cref; void interruptHandlerCref(){ PERL_SET_CONTEXT(mine); dSP; ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK; call_sv(perl_callback_cref, G_DISCARD|G_NOARGS); FREETMPS; LEAVE; } int setInterruptCref(int pin, int edge, SV* callback){ mine = Perl_get_context(); perl_callback_cref = callback; int interrupt = wiringPiISR(pin, edge, &interruptHandlerCref); return interrupt; } void pin_mode (int pin, int mode){ pinMode(pin, mode); }


    running cref handler cref handler cref handler running dler running dler Segmentation fault

    I am perplexed as to how the running line is printed numerous times, given that it should only print once, at the onset after everything else is done. This is what leads me to believe something is going very wacky with the threading somehow...

    Debug output (snipped for brevity):

    $ gdb perl GNU gdb (Raspbian 7.12-6) (gdb) r [New Thread 0x76af7470 (LWP 26138)] running cref handler Thread 1 "perl" received signal SIGSEGV, Segmentation fault. 0x000c09ec in Perl_pp_and () (gdb) bt #0 0x000c09ec in Perl_pp_and () #1 0x000c0434 in Perl_runops_standard () #2 0x000500a4 in perl_run () #3 0x0002ab50 in main ()

    The backtraces are consistently different, fwiw, but mostly they are relatively similar. I can repro several times if necessary if it'll help.



How to remove HTTP Keep-Alive 300 header from LWP::UserAgent request
2 direct replies — Read more / Contribute
by Veltro
on Apr 24, 2018 at 09:23
    Hello, I'd like to remove the Keep-Alive 300 header from the request but I can't figure out how.

    I am instantiating the LWP::UserAgent with the intention to use HTTP 1.1 and keeping the connection alive as follows:

    my $ua = LWP::UserAgent->new(keep_alive => 1, send_te => 0) ;

    send_te => 0 removes the TE header and the header information that I want to send contains tags like:
    my @ns_headers = ( 'ACCEPT' => '..', 'ACCEPT_ENCODING' => '...', 'ACCEPT-LANGUAGE => '..', 'UPGRADE_INSECURE_REQUESTS' => '1', 'USER-AGENT' => '...', ) ;
    I have tried several methods creating the request but each and one of them sends the Keep-Alive 300 header.

    my $response = $ua->get( $link, @ns_headers ) ;

    my $response = $ua->request(GET $link) ; # This does not use @ns_headers
    my $getReq = HTTP::Request->new( GET => $link, HTTP::Headers->new( @ns +_headers ) ) ; my $response = $ua->request( $getReq ) ;
    Tryig to get rid of it by specifying this in the @ns_headers does not work:

    'KEEP-ALIVE' => undef,

    Anyone knows how to do this? Thanks
paren formatter for function calls?
4 direct replies — Read more / Contribute
by iaw4
on Apr 23, 2018 at 21:36
    has someone already written a bracketed paren formatter for function calls? I am thinking increasing spaces for outer-more calls. non-function call spacing should be ignored. think
    ab + (fun1(fun2( 3 +. fun3( 4+(5+6) )))
    would become something linke
    `ab + (fun1(..fun2(.3 . + . fun3(4+(5+6)).)..)
    where I have replaced spaces with dots for clarity.
Error Using Module Spreadsheet::ParseXLSX
2 direct replies — Read more / Contribute
by roho
on Apr 23, 2018 at 10:52
    I am running Strawberry Perl 5.24 on Windows 10. I installed module "Spreadsheet::ParseXLSX". The module installed with no errors. When I "use" the module, the following error message is displayed:
    Can't load 'D:/perl/vendor/lib/auto/XML/Parser/Expat/Expat.xs.dll' for + module XML::Parser::Expat load_file:The specified module could not be found at D:/perl/lib/DynaL line 193. at D:/perl/vendor/lib/XML/ line 18. The error is definitely occurring in 'D:/perl/vendor/lib/XML/ +' line 18, which has "require XML::Parser::Expat;" in a BEGIN block. +Running perl -MXML::Parser::Expat -e 0 produces the same error messag +e.
    I double-checked module "XML::Parser::Expat" by running cpan install on it, and it says the module is up to date.
    The path and file 'D:/perl/vendor/lib/auto/XML/Parser/Expat/Expat.xs.dll' exist, so it's not clear why the above error message is displayed.

    Any suggestions are much appreciated.

    "It's not how hard you work, it's how much you get done."

Win32/MingW SetupAPI usage woes with Inline::C
2 direct replies — Read more / Contribute
by tlhackque
on Apr 22, 2018 at 21:08
    I'm probably missing something simple, but could use some help.

    Attempts to use libSetupAPI under Windows 10 using Inline::C with MingW fail to link. ActivePerl 5.22.1 MSWin32-x64-multi-thread, ActiveState 2201

    The problem is that the SetupAPI symbols fail to resolve. I have updated MinGW & Inline::C to today's latest versions. Here is a simple reproducer: (I know it doesn't do anything - it's cut down to the link issue.)

    file: #!/usr/bin/perl use 5.10.0; use warnings; use strict; use Inline( C => Config => libs => '-LC:\\MinGW\\lib -lSetupAPI', print_info => 1, BUILD_NOISY => 1, ); use Inline C => << 'EOC'; #include <windows.h> #include <stdio.h> #include <initguid.h> #include <devguid.h> #include <regstr.h> #include <setupapi.h> char *wrap_SetupDiGetClassDevs( ) { HDEVINFO hDevInfo; // Create a HDEVINFO with all present CDROM devices. hDevInfo = SetupDiGetClassDevs( &GUID_DEVCLASS_CDROM, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERF +ACE ); if (hDevInfo == INVALID_HANDLE_VALUE) croak("INVALID_HANDLE_VALUE returned"); return (char *)hDevInfo; } EOC
    Here is an attempt to load the code. Note that libsetupapi.a is included in the linker (g++) command after inline_pl_(hex).o. The undefined reference is for SetupDiGetClassDevs. The file exists, and strings show the symbol, though with the @size decoration. I must be missing some required name mapping.
    Synopsis(the output is quite cluttered): C:\PERL-5~1.1-6\site\bin\g++.exe inline_pl_7744.def \ -o blib\arch\auto\inline_pl_7744\inline_pl_7744.dll \ -mdll -s -static-libgcc -static-libstdc++ \ -L"C:\Perl-5.22.1-64\lib\CORE" \ -L"C:\MinGW\x86_64-w64-mingw32\lib" \ inline_pl_7744.o \ "C:\Perl-5.22.1-64\lib\CORE\libperl522.a" \ "C:\MinGW\lib\libSetupAPI.a" [snip...] inline_pl_7744.o:inline_pl_7744.c:(.text+0x18): undefined reference to + `__imp_SetupDiGetClassDevsA' Here is the full output (less the post-error traceback) perl -d Loading DB routines from version 1.49 Editor support available. Enter h or 'h h' for help, or 'perldoc perldebug' for more help. validate Stage <-----------------------Information Section--------------------------- +--------> Information about the processing of your Inline C code: Your source code needs to be compiled. I'll use this build directory: C:\Users\timothe\Software\Development\cdindex\_Inline\build\inline_pl_ +7744 and I'll install the executable as: C:\Users\timothe\Software\Development\cdindex\_Inline\lib\auto\inline_ +pl_7744\inline_pl_7744.dll get_maps Stage The following Inline C function(s) have been successfully bound to Per +l: char * wrap_SetupDiGetClassDevs() <-----------------------End of Information Section-------------------- +--------> Starting Build Preprocess Stage Finished Build Preprocess Stage Starting Build Parse Stage Finished Build Parse Stage Starting Build Glue 1 Stage Finished Build Glue 1 Stage Starting Build Glue 2 Stage Finished Build Glue 2 Stage Starting Build Glue 3 Stage Finished Build Glue 3 Stage Starting Build Compile Stage Starting "perl Makefile.PL" Stage Generating a dmake-style Makefile Writing Makefile for inline_pl_7744 Writing MYMETA.yml and MYMETA.json Finished "perl Makefile.PL" Stage Starting "make" Stage Running Mkbootstrap for inline_pl_7744 () "C:\Perl-5.22.1-64\bin\perl.exe" -MExtUtils::Command -e chmod -- 644 "" "C:\Perl-5.22.1-64\bin\perl.exe" -MExtUtils::Command::MM -e cp_nonempt +y -- blib\arch\auto\inline_pl_7744\inline_pl_7744.b +s 644 "C:\Perl-5.22.1-64\bin\perl.exe" "C:\Perl-5.22.1-64\lib\ExtUtils\xsubp +p" -typemap "C:\Perl-5.22.1-64\lib\ExtUtils\typemap" inline_pl_7744 +.xs > inline_pl_7744.xsc "C:\Perl-5.22.1-64\bin\perl.exe" -MExtUtils::Command -e mv -- inline_p +l_7744.xsc inline_pl_7744.c C:\PERL-5~1.1-6\site\bin\gcc.exe -c -I"C:/Users/timothe/Software/Deve +lopment/cdindex" -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -DPERL_TEXTMO +DE_SCRIPTS -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICI +T_SYS -fwrapv -fno-strict-aliasing -mms-bitfields -s -O2 -DV +ERSION=\"0.00\" -DXS_VERSION=\"0.00\" "-IC:\Perl-5.22.1-64\lib\CO +RE" inline_pl_7744.c "C:\Perl-5.22.1-64\bin\perl.exe" -MExtUtils::Mksymlists \ -e "Mksymlists('NAME'=>\"inline_pl_7744\", 'DLBASE' => 'inline_pl +_7744', 'DL_FUNCS' => { }, 'FUNCLIST' => [], 'IMPORTS' => { }, 'DL_ +VARS' => []);" C:\PERL-5~1.1-6\site\bin\g++.exe inline_pl_7744.def -o blib\arch\auto\ +inline_pl_7744\inline_pl_7744.dll -mdll -s -static-libgcc -static-lib +stdc++ -L"C:\Perl-5.22.1-64\lib\CORE" -L"C:\MinGW\x86_64-w64-mingw32\ +lib" inline_pl_7744.o "C:\Perl-5.22.1-64\lib\CORE\libperl522.a" "C: +\MinGW\lib\libSetupAPI.a" "C:\MinGW\lib\libmoldname.a" "C:\MinGW\lib\ +libkernel32.a" "C:\MinGW\lib\libuser32.a" "C:\MinGW\lib\libgdi32.a" " +C:\MinGW\lib\libwinspool.a" "C:\MinGW\lib\libcomdlg32.a" "C:\MinGW\li +b\libadvapi32.a" "C:\MinGW\lib\libshell32.a" "C:\MinGW\lib\libole32.a +" "C:\MinGW\lib\liboleaut32.a" "C:\MinGW\lib\libnetapi32.a" "C:\MinGW +\lib\libuuid.a" "C:\MinGW\lib\libws2_32.a" "C:\MinGW\lib\libmpr.a" "C +:\MinGW\lib\libwinmm.a" "C:\MinGW\lib\libversion.a" "C:\MinGW\lib\lib +odbc32.a" "C:\MinGW\lib\libodbccp32.a" "C:\MinGW\lib\libcomctl32.a" - +Wl,--enable-auto-image-base inline_pl_7744.o:inline_pl_7744.c:(.text+0x18): undefined reference to + `__imp_SetupDiGetClassDevsA' collect2: ld returned 1 exit status dmake.exe: Error code 129, while making 'blib\arch\auto\inline_pl_774 +4\inline_pl_7744.dll' [snip] dir "C:\MinGW\lib\libSetupAPI.a" Volume in drive C is Boot Disk Volume Serial Number is E315-E929 Directory of C:\MinGW\lib 06-Dec-17 15:10 319,374 libsetupapi.a

    Thanks in advance for any clues.

    This communication may not represent my employer's views, if any, on the matters discussed.

Re-ordering data branches in a [Tree::DAG_Node] tree
4 direct replies — Read more / Contribute
by atcroft
on Apr 22, 2018 at 19:07

    I am working on a project where I am looking at hierarchical data, and decided to use Tree::DAG_Node after experimenting with Introduction to Tree::DAG_Node for a while. My problem at this point, however, is that I believe I need to re-order the data. Can anyone point me to an example of re-ordering the data in a Tree::DAG_Node tree?

    If someone can point me at an example of code reordering such a tree (or suggest a better way to do what I am intending), I would greatly appreciate the assistance.

    Have a great day.

Installing Spreadsheet::XLSX
4 direct replies — Read more / Contribute
by Anonymous Monk
on Apr 21, 2018 at 04:53

    Spreadsheet::XLSX won't install on my Strawberry Perl 5.16.3, even with force. Testers on Cpan have reported this. However, on Activestate, same perl version, it is listed in their PPM and it works. So, maybe there could be some hope. Have you some idea of what I could try? The error message I get is:

    Running make install Installing C:\berrybrew\5.16.3_32\perl\site\lib\Spreadsheet\ Installing C:\berrybrew\5.16.3_32\perl\site\lib\Spreadsheet\XLSX\Fmt20 Installing C:\berrybrew\5.16.3_32\perl\site\lib\Spreadsheet\XLSX\Utili Appending installation info to C:\berrybrew\5.16.3_32\perl\lib/perlloc +al.pod MIKEB/Spreadsheet-XLSX-0.15.tar.gz C:\berrybrew\5.16.3_32\c\bin\dmake.exe install UNINST=1 -- OK Stopping: 'install' failed for 'Spreadsheet::XLSX'. Failed during this command: MIKEB/Spreadsheet-XLSX-0.15.tar.gz : make_test NO but failu +re ignored because 'force' in effect

    If there is no hope, do you know other modules to read XLSX files

Accessing module variables
5 direct replies — Read more / Contribute
by talexb
on Apr 19, 2018 at 11:04

    I want to cycle through a bunch of modules that have credentials and site URLs .. I have this working OK, but it seems that I'm doing it in a much complicated way than I should. Feedback would be appreciated.

    This script illustrates how I plan to cycle through the credential modules:

    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; { my @variables = qw/User Password Url Prefix/; foreach my $module ( qw/Foo Bar/ ) { eval "use ABCXYZ::$module"; # Foreach loop for illustration only .. could be replaced # with a map .. my %values; foreach my $var ( @variables ) { $values{ $var } = eval '$' . join ( '::', 'ABCXYZ', $module, $var ); } # Call subroutine with values hash here .. } }

    The goal is to be able to call a routine with individual site credentials for order processing. Is there a more Perl-ish way of accomplishing this? Credential modules look like this:

    package ABCXYZ::Foo; use Exporter; our @Export = ( $User $Password $Url $Prefix ); our $User = 'Joe'; our $Password = 'Secret123'; our $Url = ''; our $Prefix = 'EX'; 1;
    The credentials are stored like this so that the processing scripts can be checked into github without credentials leaving the customer site.

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Log In?

What's my password?
Create A New User
[Corion]: :-D
Corion discovers a new shiny toy to try out over the (longish) weekend. Since I've done some more with websockets, maybe I'll try writing a webserver that implements hot-reloading of HTML(+CSS, +Javascript) in the browser. Edit the local file and ...
[Corion]: ... the browser(s) get a ping to a) refresh the page or b) reload "just" the changed parts, keeping the scroll position etc.
[Corion]: But I also have to look at how I can make WWW::Mechanize:: RemoteBrowser a reality, and how to make it safe from malicious content ;)
[Corion]: Part of wanting hot-reloading is that I think I've stumbled on a very simple set of CSS that I maybe want to use for a blog, but I want to try that out on mobile too, and I also want to add/modify it slightly so it has a header too...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2018-04-26 10:45 GMT
Find Nodes?
    Voting Booth?