Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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. Post a new question!

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.

User Questions
TK param passing
1 direct reply — Read more / Contribute
by jsteng
on Apr 23, 2018 at 21:42
    I would see codes written like this:
    $submit->bind('<1>' => sub { Submit($p1, $p2, $p3, $p4, $p5); } );
    The above codes I understand, knowing how many parameters and how to intercept the params in a subroutine.



    However I dont understand this code:
    $yscroll=$mw->Scrollbar()->pack(-fill=>'y', -side=>'right',); $yscroll->configure( -command => [ \&ScrollAll, $yscroll, [$p1, $p2, $ +p3, $p4, $p5]]); sub ScrollAll { my ($sb, $wigs, @args) = @_; foreach my $w (@$wigs) { $w->yview(@args); } }


    Can anyone explain how the params are passed when it is constructed in this manner:
    -command => [ \&ScrollAll, $yscroll, [$p1, $p2, $p3, $p4, $p5]]
    In the above sub's code my ($sb, $wigs, @args) = @_;
    What is assigned to $sb?
    What is assigned to $wigs?
    Is there any other way of passing params when used with -command?
    And can that like be written like:
    -command => sub { subname ($p1, $p2, $p3, $p4, $p5); }
    thanks
paren formatter for function calls?
2 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."

Perl hash keys not considered unique
2 direct replies — Read more / Contribute
by elfstones65
on Apr 23, 2018 at 08:49

    Hi I seem to have a strange issue where adding a keys into a hash is not being considered as unique
    So say I have two files being the keys

    $file1 = 'ENV.FILESOURCE.SOURCE.J2018058.N000001'; $file2 = 'ENV.FILESOURCE.SOURCE.J2018059.N000001'; open LOG, "<$log"; while (defined($line=<LOG>)) { chomp $line; if ($line =~/File \[\/opt\/app\/data\/pulsefba\/process/) { ($processingFile) = ($line =~ /process\/(.+)]/); $files{"$processingFile"} = 1; } if ($line =~ /Finished/) { ($currentFile) = ($line =~ /process\/(.+?)]/); ($read) = ($line =~ /: Read \[(.+)\] events - Processe +d /); ($processed) = ($line =~ /Processed \[(.+?)\]/); ($wrote) = ($line =~ /Wrote \[(.+?)\]/); ($skippedRead) = ($line =~ /Skipped Read \[(.+?)\]/); ($skippedProcess) = ($line =~ /Skipped Process \[(.+?) +\]/); ($skippedWrite) = ($line =~ /Skipped Write \[(.+?)\]/) +; ($totalCount) = ($line =~ /Total Trailer Count - \[(.+ +?)\]/); $files{"$currentFile"}{'read'} = $read; $files{"$currentFile"}{'processed'} = $processed; $files{"$currentFile"}{'wrote'} = $wrote; $files{"$currentFile"}{'skippedRead'} = $skippedRead; $files{"$currentFile"}{'skippedProcess'} = $skippedPro +cess; $files{"$currentFile"}{'skippedWrite'} = $skippedWrite +; $files{"$currentFile"}{'totalTrailerCount'} = $totalCo +unt; print "Debug: $currentFile set to Read: $read\n"; print "File ENV.FILESOURCE.SOURCE.J2018058.N000001 cou +nt: $files{'ENV.FILESOURCE.SOURCE.J2018058.N000001'}{'read'}\n"; print "File ENV.FILESOURCE.SOURCE.J2018059.N000001 cou +nt: $files{'ENV.FILESOURCE.SOURCE.J2018059.N000001'}{'read'}\n"; }

    While looping through a file Output is like below. How Come is file with the J2018059 getting values in the hash for file J2018058?
    Debug: ENV.FILESOURCE.SOURCE.J2018058.N000001 set to Read: 1000
    File ENV.FILESOURCE.SOURCE.J2018058.N000001 count: 1000
    File ENV.FILESOURCE.SOURCE.J2018059.N000001 count: 1000
    Debug: ENV.FILESOURCE.SOURCE.J2018058.N000001set to Read: 2000
    File ENV.FILESOURCE.SOURCE.J2018058.N000001 count: 2000
    File ENV.FILESOURCE.SOURCE.J2018059.N000001 count: 2000
    Debug: ENV.FILESOURCE.SOURCE.J2018058.N000001 set to Read: 3000
    File ENV.FILESOURCE.SOURCE.J2018058.N000001 count: 3000
    File ENV.FILESOURCE.SOURCE.J2018059.N000001 count: 3000
    Debug: ENV.FILESOURCE.SOURCE.J2018058.N000001 set to Read: 4000
    File ENV.FILESOURCE.SOURCE.J2018058.N000001 count: 4000
    File ENV.FILESOURCE.SOURCE.J2018059.N000001 count: 4000
    Debug: ENV.FILESOURCE.SOURCE.J2018058.N000001 set to Read: 5000
    File ENV.FILESOURCE.SOURCE.J2018058.N000001 count: 5000
    File ENV.FILESOURCE.SOURCE.J2018059.N000001 count: 5000

Tk geometry, pixel coordinates precision, canvas and outline
2 direct replies — Read more / Contribute
by Discipulus
on Apr 23, 2018 at 08:07
    Hello monks and nuns!

    before the end of the Tk questions months I have another tk question.

    My goal is to have a canvas filling the mainwindow and I want to drow squares into this canvas to have evenly divided as a chessboard.

    The first question about mainwindow geometry was already answered by the wise kcott in the CB, but I also put it here for completeness and for future readers:

    • A mainwindow with geometry 100x100 goes from 0,0 to 100,100 ie it has 101 pixels! I found this very misleading.. but anyway it'snot the only problem i have.

    Infact, even using a mainwindow with geometry 99x99 I have undesired pixels here and there: in the program below I try to create 4 squares to fulfill the main canvas (but they do not arrive at the east and south borders: run it to see). Also the pixel used to outline the square are problematic..

    • canvas objects support the outline properties: is this added to the object area? I mean a square 50x50 with outline enabled (and is by default) ,means actually 51x51 one? It seems so: run my program and notice that north and west outlines are not shown as if they are outside of the visible area ( so -1,-1 as starting point).
    Notice that -outline => undef means transparent (you'll see the red of the main big canvas underlying), but specifying no outline assumes black as default .
    #!/usr/bin/perl use warnings; use strict; use Tk; # uncomment if module is installed # use Tk::WidgetDump; my ($dx,$dy); my $mw = Tk::MainWindow->new(); # kcot gently confirmed that 100x100 in geometry means # from 0,0 to 100,100 aka 101 pixels!! $mw->geometry("99x99"); # main underlying canvas is filled with RED my $can = $mw->Canvas( -height => 100, -width => 100, -bg => 'red', )->pack( ); # used to dump coordinates my %board; # alternate colors for tales my @alt_col = qw(gold2 green); # squares for tales starting at 0,0 my ($sq_x,$sq_y) = (0,0); foreach my $letter (('A'..'B')){ unshift @alt_col, pop @alt_col; foreach my $num (1..2){ # cycle colors unshift @alt_col, pop @alt_col; $can->createRectangle($sq_x, $sq_y, $sq_x+49,$sq_y+49, -fill => $alt_col[0], # outline undef means ransparent outline # if not specified defaults to black outline -outline => undef , -tags=> ['first'] ); $board{$letter.$num} = {tx=>$sq_x,ty=>$sq_y,bx=>$sq_x+49,by=>$ +sq_y+49}; # add 50 $sq_x += 50; } # reset x to 0 for new row $sq_x = 0; # add 50 to y $sq_y += 50; print "\n"; } # legenda print "ty = top Y tx = top X by = bottom Y bx = bottom X\n"; # dump board coordinates foreach my $key (sort keys %board){ print "$key -> ", ( map{"$_ $board{$key}{$_} "} reverse sort keys %{$board{$key}} ),"\n"; } $can->bind('first', '<1>', sub {&show_click();}); # uncomment if module is installed # $mw->WidgetDump; MainLoop; sub show_click{ my $ev = $can->XEvent; ($dx, $dy) = ($ev->x, $ev->y); print "CLICKED $dx $dy\n"; my $cur_id = ($can->find('withtag','current'))[0]; print "current canvas $cur_id\n\n"; }

    What the program outputs seems what I want; ie squares of 50 pixels sides:

    ty = top Y tx = top X by = bottom Y bx = bottom X A1 -> ty 0 tx 0 by 49 bx 49 A2 -> ty 0 tx 50 by 49 bx 99 B1 -> ty 50 tx 0 by 99 bx 49 B2 -> ty 50 tx 50 by 99 bx 99

    But what is shown on the screen seems misplaced toward north-west by one or more pixels. Also: when I dump the canvas I get:

    # main canvas width: 104 height: 99 reqwidth: 104 reqheight: 104 # squares coordinates dumped (from top left to bottom right) are: 0,0,49,49 50,0,99,49 0,50,49,99 50,50,99,99 # that reflect what I want

    Thanks for the patience and happy Tk month!

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Replacing keyboard functionality
2 direct replies — Read more / Contribute
by beyond.wudge
on Apr 22, 2018 at 22:08
    Hi,

    I'm a newbie to Linux and to Perl. I have half of a degree so far in software engineering and have spent a few years helping out at a small business, learning the basics of IT support. I have an input problem related to key presses executing custom code -- like a numpad key moving the mouse instead of sending a character message.

    I already have a script that:

    imports Win32::GuiTest

    declares configuration variables

    loops
    {
    if statement that checks for ( IsKeyPressed(numpad virtual key) ) then SendMouseMoveRel(arguments)
    }

    This produces the first part of the requirement -- the mouse does move with the press of a key. However, the key still sends a message to the OS. Does Perl or a module within Perl possess a function that can specifically block or intercept a key press? I understand that a hook may be required, but I'd rather try something higher level first.

    I'm developing this for both Microsoft Windows 7 and 10 and on Linux distros including Unity. I'm intending this for use both within work and home environments, at a small business and on my own desktop and laptops.

    Regards,

    beyond.wudge
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.

TK Pane->yview not working?
2 direct replies — Read more / Contribute
by jsteng
on Apr 22, 2018 at 09:19
    Trying to debug my script, I broke it down to bare minimum:
    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Pane; my $mw = MainWindow->new( ); $mw->minsize(200,300); my $pane = $mw->Scrolled( 'Pane', -scrollbars => 'e', -border => 2, )->pack(-fill=>'both', -expand=>1); foreach my $x (1..100) { my $label = $pane->Label( -text => $x, )->pack(-side=>'top', -fill=>'x', -expand=>0); # $pane->yview(moveto => 1); } MainLoop;

    Above script suppose to create a Pane, then populate it with 100 labels.
    So far so good.


    Uncommenting the line $pane->yview($label);, it is suppose to scroll to the bottom.
    But I get this error:

    Can't call method "Call" on an undefined value at C:/Perl/site/lib/Tk/Pane.pm line 346.

    What is wrong?

    According to documents (http://search.cpan.org/~srezic/Tk/Tk/Pane.pm):
    $pane->yview(moveto => 1) Is how to scroll to the very bottom but it is not doing so. Why?
Problem with perl one-liner
3 direct replies — Read more / Contribute
by LeBreton
on Apr 21, 2018 at 11:37
    Hi, i have a problem, i'm on Windows 7 with Strawberry Perl. I do : C:\Users\Documents>perl -e 'print "A"' Can't find string terminator "'" anywhere before EOF at -e line 1. I'm not a specialist of Perl, so what do i have to do to make this work ? Thanks for your help !

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":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • 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 drinking their drinks and smoking their pipes about the Monastery: (2)
    As of 2018-04-24 05:52 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?