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
Taint error on file upload
No replies — Read more | Post response
by Sanjay
on Oct 16, 2018 at 09:35

    Perl CGI giving error while using Taint when uploading a file:

    Insecure dependency in sysopen while running with -T switch at C:/Perl/site/lib/File/ line 512.

    Script works fine when Taint is not used in the shebang line. Error when Taint is on.
    #!C:/Perl/bin/perl.EXE -wT # CGI program to check Taint problem while uploading file. It prompts # for the of the file to be uploaded and displays the name of the # uploaded file. # Tested in: # OS Windows-7 32 bit, Perl 5.22.3, Apache 2.2 # OS WindowsServer-2012 64 bit, Perl 5.24.2, Apache 2.4.20 # OS Centos-6.10 64 bit, Perl 5.26.1, Apache 2.2.15 use strict; use warnings; use CGI; use CGI::Carp qw (fatalsToBrowser warningsToBrowser); my $q = new CGI; my $p_upl_new_file = $q->param ("p_upl_new_file") || ''; &sPrintForm; exit; ################################################################### sub sPrintForm { print $q->header (); print $q->start_html (); print $q->start_form ({-name => "form1"}); print $q->h1 ({-align => "center"} , "File Upload Test"); print "<br><br>"; print $q->filefield (-name => 'p_upl_new_file'); print "<br><br>"; print $q->submit (-name => "action_submit" , -value => "Submit"); print "<br><br>"; print "File name $p_upl_new_file"; print $q->end_form; print $q->end_html; } # END #############################################################
Parallel::ForkManager for any array
2 direct replies — Read more / Contribute
by MissPerl
on Oct 16, 2018 at 09:09

    I wrote this simple script after some reading online.

    To achieve fastest execution time, I want to have the number of jobs == arraysize. (any array in script for looping repeating process) I guess the other words, is instead of running stuff serially (one after the other), i have them in parallel to minimize time taken.

    So in this case I wanna delete a directory, delete the directory1 in (/user/home/directory1/), but i am clueless why it does not work, all the files and subdirectories still there. Does the script automatically assign each files/subdirectories to each children?

    Let me know if I have overlooked stuff. I am ready to learn . Thank you . :)

    #! /usr/bin/perl use Parallel::ForkManager; $directory1 = "/user/home/directory1/"; my $pm = Parallel::ForkManager->new(10); my @files = glob("$directory1/*"); my $number = scalar(@files); for (my $i = 0; $i < $number; $i++) { $pm->start and next; system ("rm", "-fr", $files[i]); exit(0); $pm->finish; } $pm-> wait_all_children;
Using big numbers correctly
1 direct reply — Read more / Contribute
by robert44444uk
on Oct 16, 2018 at 05:44

    Dear Perl Monks, I want to use the exact Chinese Remainder Theorem solution in a program I am constructing but I am not confident which of the two long numbers below will be used by the scalar $crt1 in my program, or even which of the two is correct, although my gut tells me it is the solution shown by "say" is probably the one.

    What coding should I use to ensure that $crt1 is always used correctly and printed correctly? Very grateful for your enlightenment.

    #!/usr/bin/env perl use warnings; use strict; use Math::BigFloat lib=>"GMP"; use Math::Prime::Util qw/:all/; use feature ':5.10'; my $crt1=chinese([1,2],[1,3],[1,5],[5,7],[4,11],[9,13],[0,17],[14,19], +[22,23],[28,29],[28,31],[27,37],[3,41],[15,43],[9,47],[51,53],[55,59] +,[35,61],[17,67],[35,71],[67,73],[28,79]); say $crt1; printf ("crt solution is= %.0f\n",$crt1);
Can't locate installed module
1 direct reply — Read more / Contribute
by arnauldvm
on Oct 15, 2018 at 18:28

    Installed Text::Unidecode (with no error message).


    $ perl -e 'use Text::Unidecode' Can't locate Text/ in @INC (you may need to install the Te +xt::Unidecode module) (@INC contains: ~/perl5/lib/perl5 ~/perl5/lib/p +erl5 /usr/local/Cellar/perl/5.28.0/lib/perl5/site_perl/5.28.0/darwin- +thread-multi-2level /usr/local/Cellar/perl/5.28.0/lib/perl5/site_perl +/5.28.0 /usr/local/Cellar/perl/5.28.0/lib/perl5/5.28.0/darwin-thread- +multi-2level /usr/local/Cellar/perl/5.28.0/lib/perl5/5.28.0 /usr/loca +l/lib/perl5/site_perl/5.28.0/darwin-thread-multi-2level /usr/local/li +b/perl5/site_perl/5.28.0) at -e line 1. BEGIN failed--compilation aborted at -e line 1.


    $ ls -lF ~/perl5/lib/perl5/Text total 56 drwxr-xr-x 258 xxx staff 8772 Oct 15 23:02 Unidecode/ -r--r--r-- 1 xxx staff 28162 Nov 26 2016

    Tried 3 different installation methods (cpan -i, cpanm, manual install).

    (And this module used to work on the same host few years ago. Lot's of system updates since then, though.)

    I've read numerous posts on similar topics, but couldn't find any hint to debug this.

    Context: MacOS Sierra 10.12.16, perl installed with homebrew

    $ uname -a Darwin Drogon.local 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 21 20 +:07:39 PDT 2018; root:xnu-3789.73.14~1/RELEASE_X86_64 x86_64 $ perl -e 'print $];' 5.028000

    Thanx in advance!

Simple prog isnt cooperating
3 direct replies — Read more / Contribute
by catfish1116
on Oct 15, 2018 at 17:32
    I cant get the following code to cooperate:


    use v5.12;

    use warnings;

    MY CODE:

    my $Namelist = 'Wilma Fred Barney Betty Dino';

    if ( $Namelist ~= m/\w+a/) {

    print "Matched|$<$&>$|\n";

    say "The name that matched was $1 \n";

    } else {

    print "No match: \n";


    My error(s)

    syntax error at ./exer_8_3 line 8, near "$Namelist ~"

    syntax error at ./exer_8_3 line 11, near "}"

    TIA, Catfish
how to get Config values into a hash
1 direct reply — Read more / Contribute
by Aldebaran
on Oct 15, 2018 at 16:51

    Hello monks,

    I frequently replicate others' posts so as to help if I can, learn more of a gigantic language, and have new scripts that will improve my own capabilities. So it is that chungley2000 rolled in with a question that morphed into about how to get values from Config. I've been playing with the values for a couple days now, and I wrote a script to see what output resulted from the 4 method calls that this module exports. I've commented out failed attempts to herd these values into lexical variables.

    #!/usr/bin/perl -w use 5.011; use Config qw(myconfig config_sh config_vars config_re); use Data::Dumper; say myconfig(); say "---------------"; say config_sh(); say "---------------"; say config_vars(); say "---------------"; my $ref_Env = \%ENV; say Dumper $ref_Env; my $version = config_re("version"); say "version is $version"; # my $archname = $Config{'archname'}; #produces error: %Config unknown say "---------------"; #my $ref_Config = \%CONFIG; #say Dumper $ref_Config;

    Abridged output, where I've commented on values with a double hashmark:

    Summary of my perl5 (revision 5 version 26 subversion 1) configuratio +n: Platform: osname=linux osvers=4.9.0 archname=x86_64-linux-gnu-thread-multi --------------- Author='' CONFIG='true' ## big snip from say myconfig(); zcat='' zip='zip' --------------- ##nothing for say config_sh(); --------------- $VAR1 = { 'TEXTDOMAIN' => 'im-config', 'SSH_AUTH_SOCK' => '/run/user/1000/keyring/ssh', 'IM_CONFIG_PHASE' => '2', 'PERL5LIB' => '/home/bob/perl5/lib/perl5', ## snip in ENV data 'LESSCLOSE' => '/usr/bin/lesspipe %s %s' }; version is 1 ##config_re("version"); ---------------

    My experience with the large family of Config modules has been with Config::Tiny, where I have imported such values from an .ini file. Now I would like to import the values from the myconfig() method into a hash.

    If I had to get values quick and dirty, I would create a temp file with Path::Tiny, then read it with Config::Tiny. But when you have the darn thing in memory already, it seems like a significant work-around, in particular, when you are only going to delete the file for being a security risk. I don't want these data to be persistent beyond the first few lines of a perl script. Other modules from the Config namespace seem promising, but, for example CONFIG::Hash seems like it might be the thing I'm looking for, but not quite. There are at least 12 screens of matches for Config in cpan.

    I could also use bash to pipe these values, but do I really need a shell? It seems like there could be a perl-only solution to this, which is more portable. My question then is how to to herd the = joined and newline separated values from


    into a hash.

    Thank you for your comment,

XML::Simple Data->xml element conversion problem
2 direct replies — Read more / Contribute
by GH_perler
on Oct 15, 2018 at 12:25

    Hi all, when transfering a simple data structure with XML::Simple xmlout I got an unwanted behaviour by XML::Simple.
    The basic hash as simple as it can be:

    my %xmlData; $xmlData{'Date'}='2018-10-15'; $xmlData{'Time'}='18:20:00'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'Type'} = 'D'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'ImportID'} = '123; $xmlData{'Depot'}{'Account'}{'Consignment'}{'Reference'} = 'RefNo +'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'Number'} = 'ShipN +o'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'Lifts'} = '3'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'Weight'} = '1800' +; $xmlData{'Depot'}{'Account'}{'Consignment'}{'ManifestNote'} = 'Freig +ht to load'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'CollectionDate'} = '2018- +10-15'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'DeliveryDate'} = '2018- +10-17'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'DeliveryTime'} = '15:00 +:00'; [...] Code between [...] $xmlData{'Depot'}{'Account'}{'Consignment'}{'Pallet'}='PID_987654'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'BillUnit'}{'Type'}='QP'? $xmlData{'Depot'}{'Account'}{'Consignment'}{'BillUnit'}{'Amount'}='3';

    Using this code I get mostly what I want, but unfortunately not at all

    my $xml = new XML::Simple; my $xmlout = $xml -> XMLout(\%xmlData, NoAttr => 1, RootName => 'Manif +est', KeyAttr => 'Account', NoSort => 1, SuppressEmpty => undef ); $xmlout = '<?xml version="1.0" encoding="UTF-8"?>'."\n".$xmlout;

    XML Result is like:

    <?xml version="1.0" encoding="UTF-8"?> <Manifest> <Depot> <name>Account</name> <Consignment> <Address> <Town>[...]</Town> <Type>[...]</Type> <Line>[...]</Line> <Country>[...]</Country> <County>[...]</County> <CompanyName>[...]</CompanyName> <ContactName>[...]</ContactName> <PostCode>[...]</PostCode> <Telephone>[...]</Telephone> </Address> <Address> <CompanyName>[...]</CompanyName> <PostCode>[...]</PostCode> <Town>[...]</Town> <Country>[...]</Country> <Type>[...]</Type> <Line>[...]</Line> </Address> <Lifts>[...]</Lifts> <Number>[...]</Number> <CollectionDate>[...]</CollectionDate> <Pallet>[...]</Pallet> <Reference>[...]</Reference> <BillUnit> <Type>[...]</Type> <Amount>[...]</Amount> </BillUnit> <Service> <ServiceGroupCode>[...]</ServiceGroupCode> <ServiceCode>[...]</ServiceCode> <Type>[...]</Type> </Service> <Weight>[...]</Weight> <DeliveryDate>[...]</DeliveryDate> <ImportID>[...]</ImportID> <ManifestNote>[...]</ManifestNote> <Type>[...]</Type> <DeliveryTime>[...]</DeliveryTime> </Consignment> </Depot> <Date>[...]</Date> <Time>[...]</Time> </Manifest>

    The problem ist, that I donīt get <Account>..</Account> as wrapper of <consignment>...</consignment> but <name>Account</name> (when using SuppressEmpty => undef) or <Account>Account</Account> (when not using SuppressEmpty => undef).

    Does anyone of you know why or what to configure to get the result I need?

    Thanks in advance

Inline::Python for windows 10
4 direct replies — Read more / Contribute
by tobbes
on Oct 15, 2018 at 08:19
    Greetings. As I am unable to get Inline::Python to compile properly on windows 10. Appearantly it relies on the module Proc::ProccessTable which from what I have heard does not work on windows. Is there an alternative? Or does anybody know if there is a precompiled version somewhere? I am running active state perl and I have not been able to find it in their repo. Any help would be greatly apreciated. OK, I think i may have broken something so I tried reinstalling mingw and clicked everything i could install. Now when I run cpan19> notest install Inline::Python I get this output:

    Running install for module 'Inline::Python'
    Running make for N/NI/NINE/Inline-Python-0.56.tar.gz
    Prepending C:\Perl\cpan\build\Test-Warn-0.36-2ZLr_C/blib/arch C:\Perl\cpan\build\Test-Warn-0.36-2ZLr_C/blib/lib C:\Perl\cpan\build\ExtUtils-InstallPaths-0.011-
    ePu0hw/blib/arch C:\Perl\cpan\build\ExtUtils-InstallPaths-0.011-ePu0hw/blib/lib C:\Perl\cpan\build\ExtUtils-Config-0.008-7dv9vN/blib/arch C:\Perl\cpan\build\ExtUtils-Config-0.008-7dv9vN/blib/lib C:\Perl\cpan\build\ExtUtils-Helpers-0.026-5pberY/blib/arch C:\Perl\cpan\build\ExtUtils-Helpers-0.026-5pberY/blib/lib C:\Perl\cpan\build\ExtUtils-PL2Bat-0.001-sr4UpL/blib/arch C:\Perl\cpan\build\ExtUtils-PL2Bat-0.001-sr4UpL/blib/lib to PERL5LIB for 'get' Has already been unwrapped into directory C:\Perl\cpan\build\NINE-ELKF6g
    Prepending C:\Perl\cpan\build\Test-Warn-0.36-2ZLr_C/blib/arch C:\Perl\cpan\build\Test-Warn-0.36-2ZLr_C/blib/lib C:\Perl\cpan\build\ExtUtils-InstallPaths-0.011-ePu0hw/blib/arch C:\Perl\cpan\build\ExtUtils-InstallPaths-0.011-ePu0hw/blib/lib C:\Perl\cpan\build\ExtUtils-Config-0.008-7dv9vN/blib/arch
    C:\Perl\cpan\build\ExtUtils-Config-0.008-7dv9vN/blib/lib C:\Perl\cpan\build\ExtUtils-Helpers-0.026-5pberY/blib/arch C:\Perl\cpan\build\ExtUtils-Helpers-0.026-5pberY/blib/lib C:\Perl\cpan\build\ExtUtils-PL2Bat-0.001-sr4UpL/blib/arch C:\Perl\cpan\build\ExtUtils-PL2Bat-0.001-sr4UpL/blib/lib to PERL5LIB for 'make' 'C:\Perl\bin\perl.exe Makefile.PL INSTALLDIRS=site' returned status 512, won't make
    Skipping test because of notest pragma
    Running make install
    Make had some problems, won't install

    Which isn't very helful to me, it seems it is just a general fail to make. Also it says it can't make clean because it is missing a Makefile, which i suppose is bad. I tried downloading the tar and doing the installation manually. appearantly I have a too old version of ExtUtils::MakeMaker

    > upgrade ExtUtils::MakeMaker
    > install ExtUtils::MakeMaker
    results in:
    Catching error: "Modification of non-creatable hash value attempted, subscript \"build_requires\" at C:/Perl/lib/ line 9734.\cJ\cI...propagated at C:/Perl/lib/ line 3266.\cJ" at C:/Perl/lib/ line 281. CPAN::shell() called at C:\Perl\bin/cpan.bat line 211
    Maybe it's time to give up? Is it at all possible to get cpan to play nicely with windows? I am running perl 5.10 from active state.

Having trouble getting Rex (Remote Execution) module to generate output
1 direct reply — Read more / Contribute
by nysus
on Oct 14, 2018 at 15:27
DBD::MariaDB or DBD::Mysql
3 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 14, 2018 at 04:32
    I'm confused.For accessing Mysql which driver do I use?

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.