Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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
How to remove HTTP Keep-Alive 300 header from LWP::UserAgent request
1 direct reply — 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 +oader.pm line 193. at D:/perl/vendor/lib/XML/Parser.pm line 18. The error is definitely occurring in 'D:/perl/vendor/lib/XML/Parser.pm +' 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: inline.pl #!/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 inline.pl Loading DB routines from perl5db.pl 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 " +inline_pl_7744.bs" "C:\Perl-5.22.1-64\bin\perl.exe" -MExtUtils::Command::MM -e cp_nonempt +y -- inline_pl_7744.bs 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\XLSX.pm Installing C:\berrybrew\5.16.3_32\perl\site\lib\Spreadsheet\XLSX\Fmt20 +07.pm Installing C:\berrybrew\5.16.3_32\perl\site\lib\Spreadsheet\XLSX\Utili +ty2007.pm 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 = 'www.example.com'; 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.

what difference between eval and do ?
2 direct replies — Read more / Contribute
by Anonymous Monk
on Apr 18, 2018 at 23:14
    I thought do BLOCK and eval BLOCK were the same except the last one traps error. But I'm wrong!
    my @dd = (1..10); grep { s/\d+/a/ } do {@dd}; print @dd; # aaaaaaaaa +a my @dd = (1..10); grep { s/\d+/a/ } eval{@dd}; print @dd; # 123456789 +10
    seems 'eval' make a copy but 'do' not, any comment?
Win32::CreateProcess problem
2 direct replies — Read more / Contribute
by mdamazon
on Apr 18, 2018 at 22:32
    I can execute Win32::CreateProcess in a loop succesfully. Now I want to prevent my script from moving forward until all the child processes that were created in the loop have exited. This is causing problems. The code inside the first foreach loop below executes properly. The code below inside the while loop which attempts to detect the status of the child processes is not.

    use Win32::Process qw(CREATE_NEW_CONSOLE STILL_ACTIVE); use Win32; my %procs=(); foreach my $a (@array) { my $cmd01 = 'some command ' . $a . ' other stuff'; my $cmd = "cmd /c echo Performing job. Please wait... +& $cmd01"; my $ProcessObj; Win32::Process::Create($ProcessObj,"C:\\WINDOWS\\syste +m32\\cmd.exe","$cmd01",0,CREATE_NEW_CONSOLE,"."); $procs{$ProcessObj} = $a; } while (%procs) { foreach my $key (keys %procs) { my $exit_code = 1; $key->GetExitCode($exit_code); while($exit_code == Win32::Process::ST +ILL_ACTIVE()) { sleep(1); $key->GetExitCode($exi +t_code); } print "GetExitCode returned $exit_code +, exiting main process for $procs{$key}.\n"; delete $procs{$key}; } }

    This returns:

    Can't locate object method "GetExitCode" via package
    "Win32::Process=SCALAR(0x6e604a4)" (perhaps you forgot to load "Win32::Process=SCALAR(0x6e604a4)"?) at ..\code\script.pl line 1498, <STDIN> line 1 (#1)
    Uncaught exception from user code:
    Can't locate object method "GetExitCode" via package "Win32::Process=SCALAR(0x6e604a4)" (perhaps you forgot to load "Win32::Process=SCALAR(0x6e604a4)"?) at ..\code\script.pl line 1498, <STDIN> line 1.

shebang anomaly
3 direct replies — Read more / Contribute
by perlboy_emeritus
on Apr 18, 2018 at 17:09
    Hello Monks,

    I run Perl natively in macOS (v5.18.2) and in perlbrew (v5.20.3) and in debian in a VirtualBox vm (v5.24.1). The Perl code is common by design, meant to be portable and shared by all of these separate Perl environments, so my shebang line is:

    #!/usr/bin/env perl -w or #!/usr/bin/env perl -wd

    depending on whether I wish to debug. This shebang works correctly in macOS, either the native perl or the perlbrew perl but in debian env does not like either the -w or the -wd arguments. This, despite the (relatively) common man pages for env that assert that the command handed to env can take arguments, as in:

    macOS:

    env [-iv] [-P altpath] [-S string] [-u name] [name=value ...] [utility [argument ...]]

    debian:

    env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]

    When I run perl scripts shared from macOS in debian I have to remove -w or -wd, otherwise I get:

    /usr/bin/env: 'perl -w': No such file or directory

    The single quotes in that error message are from bash, not my script. I have tried to quote -w and -wd but explicitly quoting those arguments does not change the outcome. The bash shell or env or whatever are treating -w and -wd as the names of files and failing to find either, barf that error message. It is important that I be able to share Perl scripts between all of these execution environments so the shebang must be the same in all. What is debian env doing that the native macOS env is not? Is this possibly a bug in GNU env (v8.26)?

    I suppose, technically, this is not a Perl question, so perhaps I should post this to stack overflow or some other technical site, but I thought I'd try Monks first.

How to read a file containing filenames and pass as input to perl script?
1 direct reply — Read more / Contribute
by Kal87
on Apr 18, 2018 at 15:53
    Hi there, I'm using the below perl script to process an XML file where the filename is passed as an argument during runtime (Argv[0]) to the script. This works well, however, I would like to take this up a notch. I have another file (let's call it filename_list.txt) that contains a list of filenames (with absolute paths). Say the first two lines in that file read like this:
    /home/kal/assemble.xml /home/tom/Venice.xml
    I expect thousands of lines in filename_list.txt I'm looking to update the script so that it reads each line of filename_list.txt, and executes the twig and CSV bit for each file. Not sure how to get this going, could someone please help? I've attempted to use another bash script with a while, but it would be great if someone could suggest a faster method that involves just this perl script.
    use Text::CSV_XS; use XML::Twig; my $csv = Text::CSV_XS->new({'sep_char' => "|",}, ); my $twig = XML::Twig->new( ); twig_handlers => {'EDI_DC40' => \&process_EDI_DC40,}, ); $twig->parsefile( $ARGV[0] ); sub process_EDI_DC40 { my( $twig, $thingy ) = @_; my @values = map { $thingy->first_child( $_ )->text } qw(DOCNUM MESTYP SNDPRN RCVPOR RCVPRN); $csv->say( *STDOUT, \@values ); + }
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2018-04-25 15:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?