Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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
Trouble writing to SQLite from CGI on Windows
2 direct replies — Read more / Contribute
by RedJeep
on May 21, 2019 at 02:09

    Hello folks. I have two Windows 10 computers. Running IIS. Both configured identically... well, as best as I can tell. I am trying to create a very basic CGI web site that registers users to a SQLite database. On one server, it works fine. On my desktop system the CGI page with database INSERT does not kick off any errors (that I can see) but it does not INSERT the new record. But, what is really odd, is that if I try and submit the same data again, I get a Unique Constraint error. The database has only three columns (fname, lname and email). "email" has a constraint.

    Following is a snippet of the code used to create the database
    my $sql = <<'END_SQL'; CREATE TABLE people ( id INTEGER PRIMARY KEY, fname VARCHAR(100), lname VARCHAR(100), email VARCHAR(100) UNIQUE NOT NULL,

    But, again I have this running fine on another system. Following is my test code. I have stripped out passing params and hard-coded the variables of fname, lname and email. The database currently only has one record so there are no obvious constraints.

    What seems really odd to me is that the new record is not being written. No error kicked off (that I can see). But if I try to resubmit the same data (the same email) then I get the error of.

    Output on first try submitting a new record from browser. But it does not actually write to the database

    Test 103
    dbfile: /inetpub/wwwroot/data/cgi_test1.db

    Output on second try submitting that same record from browser. But, again, it does not actually write to the database.

    Software error:
    DBD::SQLite::db do failed: UNIQUE constraint failed: at C:\inetpub\wwwroot\ line 31.
    For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.

    And I copy the same script to my other Windows 10 IIS server and it works fine. Or, I run from the command line and it INSERTs successfully.I know I should move on from CGI, but this is a small site and typically this sort of thing is super easy to do.

    Following is output from SQLite query:

    C:\inetpub\wwwroot\data>sqlite3 cgi_test1.db
    SQLite version 3.22.0 2018-01-22 18:45:57
    Enter ".help" for usage hints.
    sqlite> select * from people;

    I appreciate any insight that you could provide. I don't think I have a Perl script problem. Maybe one of you has seen this. I just don't know.

    #!/usr/local/bin/perl ### Setup environment use CGI; use CGI::Carp qw(fatalsToBrowser); use CGI::Session; use CGI::Session qw/-ip-match/; use DBI; my $q = CGI->new; ### People my $dbfile = "/inetpub/wwwroot/data/cgi_test1.db"; my $dsn = "dbi:SQLite:dbname=$dbfile"; my $user_a = ""; my $password_a = ""; my $dbh = DBI->connect($dsn, $user_a, $password_a, { PrintError => 0, RaiseError => 1, AutoCommit => 0, FetchHashKeyName => 'NAME_lc', },) or die $dbh::errstr; my $fname = 'Joe'; my $lname = 'Smith'; my $email = ''; $dbh->do('INSERT INTO people (fname, lname, email) VALUES (?, ?, ? +)', undef, $fname, $lname, $email); $dbh->commit(); $dbh->disconnect(); print "Content-Type: text/html\n\n"; print "<html> <head>\n"; print "<title>Test</title>"; print "</head>\n"; print "<body>\n"; print "<h3>Test 103</h3>\n"; print "dbfile: $dbfile <br>\n"; print "lg_name: $email <br>\n"; print "</body> </html>\n";
Modernizing a Deploy script to standard distro v5.10.1
3 direct replies — Read more / Contribute
by rje
on May 20, 2019 at 10:58

    Good morning fellow monks.

    On purpose, I volunteered to update a deploy script. The current script is a Perl 4 stand-alone script that copies files into their proper deployment locations.

    How you would do this?

    I sold my boss on moving common code into a package, because it would (1) hide and reuse duplicated code, (2) shorten new typical deploy scripts dramatically; (3) potentially reduce accidental errors, (4) introduce such innovations as use strict; and use warnings; and (5) give the systems team a tiny bit of control over code maintainability, as opposed to 'no control' today.

    CONSTRAINT: I'm limited to the standard distribution for v5.10.1. I can't install packages.

    I'm thinking of a package that minimizes the "visual change" of the existing way, but adds a healthy dose of SAFER.

    Here's a very typical example. Note the lack of safe practices.

Problems with strings
4 direct replies — Read more / Contribute
by baxy77bax
on May 20, 2019 at 05:32
    Given a set of strings S of fixed length |S|=l and alphabet = {a,b,c} such that:
    aaaaaaaaabababacbbbbbbbaccaabc aaaaaaaaaaaaaaaaacbbbbbbbaaaca aaaaaaaaabaaaaabbaaaaabaaccccc
    what transforms can i apply to homogenize them by either:

    a) grouping same characters together within each string
    b) grouping same characters together across all strings (e.g. have most aaa's in one, bbb's in the other, etc. - of course, sorting does not count as the number of character occurrences does not change per string)
    c) transform (map) characters e.g. a-> b
    d) something else

    However, conditions are:
    a) the size of the original input data cannot be smaller than its transform, meaning the index needs to be implicitly built into the data (in the same way BWT does it).
    b) Types of queries that need to be supported:
    What is the character on i-th position of the original string. where 0<=i<=l.

    Some of the obvious solutions are:

    a) BWT
    b) BWT using all strings
    c) replace a with b and record coordinates using either bitstrings or ints (but this violates the size condition unless there is a smart way to record positions within the strings itself somehow)
    d) something else

    Has anyone encountered this problem before? How did you solve it?


environment and locations
1 direct reply — Read more / Contribute
by Anonymous Monk
on May 19, 2019 at 07:28

    I am trying to retrieve the pdf hashes via a JohnTheRipper script, which can be found at (can't link it - get "permission denied") magnumripper/JohnTheRipper/bleeding-jumbo/run/ under

    I have media-libs/exiftool-11.29 installed in the standard destination for my distribution (and media-libs/libexif-0.6.21-r2 installed, as well).

    The relevant part of the environment:

    $ perl -V [...] @INC: /etc/perl /usr/local/lib64/perl5/5.26.2/x86_64-linux /usr/local/lib64/perl5/5.26.2 /usr/lib64/perl5/vendor_perl/5.26.2/x86_64-linux /usr/lib64/perl5/vendor_perl/5.26.2 /usr/local/lib64/perl5 /usr/lib64/perl5/vendor_perl /usr/lib64/perl5/5.26.2/x86_64-linux /usr/lib64/perl5/5.26.2
    The location of the module:
    $ ls -al /usr/lib/perl5/vendor_perl/5.26.2/Image/ total 468 drwxr-xr-x 3 root root 4096 2019-05-16 02:15:48 ./ drwxr-xr-x 17 root root 4096 2019-05-16 02:22:43 ../ drwxr-xr-x 4 root root 4096 2019-05-16 02:15:48 ExifTool/ -r--r--r-- 1 root root 352517 2019-05-16 02:15:38 -r--r--r-- 1 root root 100000 2019-05-16 02:15:38 ExifTool.pod
    The initial error:
    $ perl file.pdf Can't locate in @INC (you may need to install the ExifTool + module) (@INC contains: ./lib /etc/perl /usr/local/lib64/perl5/5.26. +2/x86_64-linux /usr/local/lib64/perl5/5.26.2 /usr/lib64/perl5/vendor_ +perl/5.26.2/x86_64-linux /usr/lib64/perl5/vendor_perl/5.26.2 /usr/loc +al/lib64/perl5 /usr/lib64/perl5/vendor_perl /usr/lib64/perl5/5.26.2/x +86_64-linux /usr/lib64/perl5/5.26.2) at line 39. BEGIN failed--compilation aborted at line 39.
    Of course, I did some searching before coming here, and found a suggested fix:
    $ perl -I /usr/lib64/perl5/vendor_perl/5.26.2/Image/ file. +pdf Name "ExifTool::configFile" used only once: possible typo at pdf2john. +pl line 36. Name "ExifTool::langs" used only once: possible typo at li +ne 771. Name "ExifTool::charsetName" used only once: possible typo at pdf2john line 589. Name "ExifTool::langName" used only once: possible typo at + line 771. Can't locate object method "new" via package "ExifTool" at + line 403.
    At this point, I am completely baffled as to why ExifTool can't find the "new" method.

    Any idea what is going on? Thank you in advance for your assistance.

Windows Tk issue Copy and Paste Russian keyboard
2 direct replies — Read more / Contribute
by IB2017
on May 19, 2019 at 05:36

    Hello Monks

    on Windows, with the latest Tk version, using a Russian keyboard layout, I am not able to use the ubiquitous shortcuts for copy and paste (Ctrl+C and Ctrl+V) with any widget. Is there a reason while Tk does not know this shortcuts if the layout is set to Russian (no problem if set on other languages)? Is there some workaround this issue? Thank you for any suggestions that will point me in the right direction.

Can't find or uninstall version of perl
3 direct replies — Read more / Contribute
by ScarletObsidian
on May 19, 2019 at 02:37
    Hello Monks,

    I have an annoying problem that I've been wrestling with for the last few hours. It's one of those tiny, but very annoying things that completely hamstrings you, while also being entirely orthogonal to the work you actually need to accomplish. It appears that I have two version of Perl somewhere on my machine and that it's causing a whole bunch of problems. I want to use the last Strawberry Perl, and would love to delete the older version 5.26.2 in favor of (64 bit), but I can't find 5.26.2 on my computer! When I enter "which perl" into terminal, it tells me that the path is /usr/bin/perl, but I can't find that path anywhere on my computer. Even if I could, I realize that I don't know how to go about uninstalling a version of perl that doesn't seem to have come from a standard distribution like Strawberry.

    Please help me overcome this so I can go back to trying to solve my actual problem! I just want to delete this old version of perl so that I can do everything with the new version.

    Thanks in advance.

Using $# defines a variable?
2 direct replies — Read more / Contribute
by smittypaddler
on May 18, 2019 at 17:21
    Why does using $# define a previously undefined variable?
    #!/usr/bin/perl $array=undef; warn "array ",defined($array) ? 'is' : 'is not'," defined"; warn '$#{$array} is ',$#{$array}; warn "array ",defined($array) ? 'is' : 'is not'," defined";
    Produces this:
    array is not defined at /home/smitty/bat/t line 3. $#{$array} is -1 at /home/smitty/bat/t line 4. array is defined at /home/smitty/bat/t line 5.
parsing Palm databases
1 direct reply — Read more / Contribute
by morgon
on May 17, 2019 at 20:25

    I am a bit reluctant to ask this (as it sort of reveals how old I have become) but I finally retired my Palm about a year ago.

    However I still want to hold on to some information stored on the device, so I am trying to parse the datebook and memo pdbs from a backup with perl.

    Datebook seems to work, I can e.g. do this

    use strict; use Data::Dumper; use Palm::Datebook; my $pdb = new Palm::Datebook; $pdb->Load("CalendarDB-PDat.pdb"); print Dumper($pdb);
    And this produces something I can process further, however parsing memos does not work at all:
    use strict; use Data::Dumper; use Palm::Memo; my $pdb = new Palm::Memo; $pdb->Load("MemosDB-PMem.pdb"); print Dumper($pdb);
    This simply dies with

    "No handler defined for creator "PMem", type "DATA"

    It's been years since I last tried to parse pdbs with perl and while I can (vaguely) remember that I've had issues in the past I cannot remember anything, so I am looking for a way to parse palm memo-databases in perl...

    Many thanks!

Regex variables with delimiters
7 direct replies — Read more / Contribute
by clerew
on May 17, 2019 at 20:24

    I have a file with lines of the form

    /dev/sda4 6 Fri Apr 12 04:30:02 2019 +0100   /dumpx/DUMP4X/var/level6/55    86.53 MB

    and I have another file with lines of the form


    and I would like to find (and remove) all the lines in the first file which contain the strings in the second file. Fortunately, I can assume that both files are sorted in the same order.

    to find a single entry is simple:

    if $line =~ m?/dumpx/DUMP4X/var/level6/55? then do something

    but what I want to do is to read lines from the two files in a suitable loop, picking out the matches, so I need a $regexp variable

    So I write

    $regexp = "m?" . <STDIN> . "?";

    (the second file is actually coming from a pipe)

    and then I test

    if $line =~ $regexp ...

    and if it matches, then I do the necessary stuff, and fetch the next $line and obtain the next $regexp.

    But the =~ operator has been cunningly designed so that does not work. Essentially, if the RHS of =~ is a variable (my $regexp), then there is a builtin assumption that it uses '/' delimiters which, for my case, are totally unsuitable.

    So how do I do this job?

Mojolicious: Optional placeholder and template name
1 direct reply — Read more / Contribute
by frazap
on May 17, 2019 at 10:16
    I have a small Mojolicious app that display a page
    And load a libmap.html.ep template in the ./template folder.

    This file uses js files that are in the ./public folder.

    I would add a locale in the url:  ....:3000/fr/libmap, without having any other change in the path of the template or public folders,

    I tried

    $r->get('/:loc/libmap')->to(template => 'libmap', loc=> 'en');
    but it fails with Page not found...

    What am I missing ?


    Edit: I have a utils.js file that is searched in public/fr/utils.js folder instead of public/utils.js folder.

    That were the problem is... How can I keep on with having all my js files in ./public and not in public/fr, public/en ... ?

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.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (5)
    As of 2019-05-21 10:31 GMT
    Find Nodes?
      Voting Booth?
      Do you enjoy 3D movies?

      Results (132 votes). Check out past polls.

      • (Sep 10, 2018 at 22:53 UTC) Welcome new users!