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 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 !
pp hide console GUI
3 direct replies — Read more / Contribute
by IB2017
on Apr 21, 2018 at 08:48

    Dear monks

    Here I am again with the following question. When I pack my Tk app with pp, The -gui option hides the console window. However, however when I lunch the application, the console window is displayed for a fraction of a second, to be then hidden. Is this a feature, a bug, or something I have to live with? It is not the end of the world... but it is not really how it should be in a GUI application.

    I am on Windows 10, perl 5.16, and I have the latest pp installed

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

REGEX help
4 direct replies — Read more / Contribute
by Mike98mm
on Apr 20, 2018 at 19:51
pp concatenate path
4 direct replies — Read more / Contribute
by Anonymous Monk
on Apr 20, 2018 at 16:44

    Windows 10, Strawberryperl 5.16.3, pp

    If I pack the following two scripts with pp, the first work, the second not (Can't connect to data source 'DBI:SQLite:\C:\Users\DON\Desktop\data.db' because I can't work out what driver to use (it doesn't seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is not set) at script/myscript.pl). In the first, the database path is hard encoded, in the second it is read by a configuration file (in the example a simple text file). Note that both works nicely from command line

    use warnings; use strict; use DBI; use DBD::SQLite; my $Path='C:\Users\DON\Desktop\data.db'; my $dsn = "DBI:SQLite:" . $Path; print "Connecting $dsn ... \n"; my %attr = (RaiseError => 1, sqlite_unicode => 1, AutoCommit = +> 1); my $dbh = DBI->connect($dsn, "", "", \%attr) || die $DBI::errs +tr; print "done!\n";

    And here the second script, reading the same $Path value from file

    use warnings; use strict; use DBI; use DBD::SQLite; my $Path; print "Reading configuration file...\n"; my $FileInput="config.txt";#simple txt file containing this: C +:\Users\DON\Desktop\data.db open my $FH, "<:encoding(UTF-8)", $FileInput; while (my $line = <$FH>) { $Path = $line; } my $dsn = "DBI:SQLite:" . $Path; print "Connecting $dsn ... \n"; my %attr = (RaiseError => 1, sqlite_unicode => 1, AutoCommit = +> 1); my $dbh = DBI->connect($dsn, "", "", \%attr) || die $DBI::errs +tr; print "done!\n";

    What is wrong in the second script that pp doesn't like?

$chart->add_series ERROR
1 direct reply — Read more / Contribute
by nashx
on Apr 20, 2018 at 14:59

    I am using Strawberry Perl & Getting a blank chart ( excel) . I want to pass a variable for values

    $rx=101; $chart->add_series( name => 'HISTOGRAM', categories => '=Sheet1!$A$1:$A$\$rx', ## this works values => '=Sheet1!$B$1:$B$\$rx', ## does not work . get + a blank chart . ); $chart->add_series( categories => [ 'Sheet1', 1, 6, 0, 0 ], values => [ 'Sheet1', 1, 6, 2, 2 ], );
    Above does not work. When executed get error "Unknown defined name ARRAY in formula
Tk bind key hexadecimal value
2 direct replies — Read more / Contribute
by Anonymous Monk
on Apr 20, 2018 at 09:53

    The following script is nonsense but it shows my goal. I want to "remap" the keyboard and be able to bind the keyboard key to the hexadecimal value of the keyboard: F1 -> 0x70.

    use strict; use warnings; use Tk; our $name; my $mw = MainWindow->new(); my $entry = $mw->Entry( -textvariable => \$name )->pack(); $mw-> bind('<F1>', sub{entervalue()}); $mw->MainLoop(); exit(0); sub entervalue{ $name = "xxx"; }

    I need this solution because I do want to "jump" the layout of a specific keyboard and assign a defined character/string to a specific physical key. Is this possible?

qx + sed not working
3 direct replies — Read more / Contribute
by Maestro815
on Apr 20, 2018 at 07:51

    Hi Guys, Would just like to ask for your wisdom on what approach can I do to make sed work with qx on a loop. It is working on the first loop but failing on the succeeding loops. Thanks in advance.

    foreach (@SetBCs) { my $command = qx(sed -n "/Sets/,/Rules/p" $_); print $command; }
pp macOS external file
2 direct replies — Read more / Contribute
by IB2017
on Apr 20, 2018 at 07:06

    Hi monks

    time again to ask for your knowledge. I am encountering the following problem with an executable created with pp on macOS. The executable needs to read files (for example parameters files) which are in the same directory of the executable. If I run the script from the command line, the files are read without problems. If I run the executable, the files cannot be read. So there must be some problem with my paths. To explain this, a simple Tk example with a button and an icon:

    use strict; use warnings; use Tk; use Tk::PNG; my $png = 'myicon.png'; my $mw = Tk::MainWindow->new(); my $icon = $mw->Photo(-file => $png); my $btn = $mw->Button( -image => $icon, ); $btn->pack(); $mw->MainLoop();

    I create my executable simply with the command:

    pp -o TEST myscript.pl

    When I run the executable I get the following error:

    couldn't open "myicon.png": no such file or directory

    This of course signals that it can not find the file. From the command line however it works.

    What should I consider to solve this?

Add your question
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.