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
Requring minimum perl version in a cpanfile
2 direct replies — Read more / Contribute
by Anonymous Monk
on Jan 19, 2017 at 17:12
    I am using cpanfile with my app to try to make it easier to install for non-perl users. I added a line in cpanfile specifying the minimum perl version, but I was expecting it to bail if the requirement wasn't met. Instead, it only prints a line after it tries to install everything, saying the perl version isn't in the specified range. I also added the requires line inside an on 'configure' => sub { }, but it behaves the same. Is there a way to make it bail on the perl version, before it wastes time trying to install a bunch of modules?
Strawberry CPAN
3 direct replies — Read more / Contribute
by LloydRice
on Jan 19, 2017 at 17:11
    With Strawberry Perl, what is the preferred way to load CPAN modules? Should I go with the standard CPAN thing, or does Str. have a better way?
Browser Fingerprint
No replies — Read more | Post response
by freedurt
on Jan 19, 2017 at 16:06
    Hi PerlMonks

    I am looking for a solution to do some browser fingerprinting that goes beyond an IP check. I want to validate if someone coming into a CGI script is from a device I have seen in the past with some reasonable accuracy that is not an IP or Cookie check. I understand this is not fool-proof and users can and will switch browsers but nonetheless I would like to do a browser digital fingerprint and then exclude.

    So the question is... any code or module someone can provide that gives a reasonable browser digital fingerprint algorithm?

    It needs sit in the middle of being restrictive but not too restrictive (i.e. you could not just check useragent and say you are disallowed because the same useragent has already been seen).

    Based on my reading it would seem a combo between user agent and browser plugin details would work but I am not sure perl CGI can get plugin details?

    User Agent (1 in 4,184)
    HTTP_ACCEPT Headers (1 in 14)
    Browser Plugin Details (1 in 1.8 million)
    Time Zone (1 in 24)
    Screen Size and Color Depth (1 in 1,700)
    System Fonts (1 in 11)
    Cookies Enabled? (1 in 1.3)
    Limited SuperCookie test (1 in 2)


    Thanks in advance for the help!

Unknown charnames when building Encode
2 direct replies — Read more / Contribute
by yulivee07
on Jan 19, 2017 at 03:23
    Hello fellow Perlmonks, I am trying to build Encode 2.88-3 from CPAN on AIX 7.2. During the make test phase I receive various errors about unknown characters:
    Use of uninitialized value $txt in pattern match (m//) at /usr/opt/per +l5/lib/5.20.1/_charnames.pm line 499. Unknown charname 'alpha' at t/Encode.t line 44, within string BEGIN not safe after errors--compilation aborted at t/Encode.t line 14 +8. t/Encode.t ................. t/encoding-locale.t ........ ok Use of uninitialized value $txt in pattern match (m//) at /usr/opt/per +l5/lib/5.20.1/_charnames.pm line 459. Unknown charname 'LATIN SMALL LETTER SHARP S' at t/encoding.t line 77, + within string BEGIN not safe after errors--compilation aborted at t/encoding.t line +165. Use of uninitialized value $txt in pattern match (m//) at /usr/opt/per +l5/lib/5.20.1/_charnames.pm line 459. Unknown charname 'POUND SIGN' at t/mime-header.t line 166, within stri +ng Execution of t/mime-header.t aborted due to compilation errors. # Looks like your test exited with 2 just after 1. t/mime-header.t ............
    To test whether this is an AIX problem or a perl problem, I tried to build the same version on my linux system, where Encode installs just fine.
    To pick the first error:
    is "\N{alpha}",substr($uni,0,1),"alpha does not map to symbol 'a'";
    It seems AIX perl is unable to find the \N{alpha} character. I am a bit lost here - where does perl usually search for characters like this?
    I need a hint into the direction I have to search for with this problem. Can someone provide some debugging tips?
    perl -E 'use charnames (); say $charnames::VERSION' 1.40 perl -C -E 'say "\x{3b1} - \x{df} - \x{a3}"' Wide character in say at -e line 1. α - - perl -E 'use Unicode::UCD; say $Unicode::UCD::VERSION' 0.58 perl -MUnicode::UCD=charprops_all -E 'say charprops_all("U+$_")->{Age} + for qw{3b1 df a3}' "charprops_all" is not exported by the Unicode::UCD module Can't continue after import errors at -e line 0. perl -C -E 'say "\N{greek:alpha}"' Use of uninitialized value $txt in pattern match (m//) at /usr/opt/per +l5/lib/5.20.1/_charnames.pm line 459. Use of uninitialized value $txt in pattern match (m//) at /usr/opt/per +l5/lib/5.20.1/_charnames.pm line 499. Unknown charname 'greek:alpha' at -e line 1, within string Execution of -e aborted due to compilation errors.
    The build process is using CPAN (perl -MCPAN -eshell) to install modules. We use local::lib to install to a specific directory, rather than the system perl path. The perl we are using is the one coming with AIX 7.2, so we did not build perl ourself.
    perl -V Summary of my perl5 (revision 5 version 20 subversion 1) configuration +: Platform: osname=aix, osvers=, archname=aix-thread-multi uname='aix blade08 1 6 00003c3ad100 ' config_args='-d -Dprefix=/usr/opt/perl5 -Dcc=xlc_r -Duseshrplib -D +usethreads' hint=recommended, useposix=true, d_sigaction=define useithreads=define, usemultiplicity=define use64bitint=undef, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='xlc_r -q32', ccflags ='-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX +_SOURCE -qmaxmem=-1 -qnoansialias -qlanglvl=extc99 -DUSE_NATIVE_DLOPE +N -DNEED_PTHREAD_INIT -q32 -D_LARGE_FILES', optimize='-O', cppflags='-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem= +-1 -qnoansialias -qlanglvl=extc99 -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_ +INIT' ccversion='', gccversion='', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='ld', ldflags =' -brtl -bdynamic -b32' libpth=/lib /usr/lib /usr/ccs/lib libs=-lbind -lnsl -ldbm -ldl -lld -lm -lcrypt -lpthreads -lc perllibs=-lbind -lnsl -ldl -lld -lm -lcrypt -lpthreads -lc libc=, so=a, useshrplib=true, libperl=libperl.a gnulibc_version='' Dynamic Linking: dlsrc=dl_aix.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -bE:/usr/ +opt/perl5/lib/5.20.1/aix-thread-multi/CORE/perl.exp' cccdlflags=' ', lddlflags='-bhalt:4 -G -bI:$(PERL_INC)/perl.exp -b +E:$(BASEEXT).exp -bnoentry -lpthreads -lc -lm' Characteristics of this binary (from libperl): Compile-time options: HAS_TIMES MULTIPLICITY PERLIO_LAYERS PERL_DONT_CREATE_GVSV PERL_HASH_FUNC_ONE_AT_A_TIME_HARD PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP PERL_NEW_COPY_ON_WRITE PERL_PRESERVE_IVUV USE_ITHREADS USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF USE_REENTRANT_API Built under aix Compiled at Feb 6 2015 14:54:29 %ENV: PERL5LIB="/home/perl_ss/perl5/lib/perl5/aix-thread-multi:/home/per +l_ss/perl5/lib/perl5:/usr/local/lib/site_perl/5.8.8:/usr/local/site_p +erl/common" PERL5OPT="" PERL5_CPANPLUS_IS_RUNNING="9961732" PERL5_CPAN_IS_RUNNING="9961732" PERL_LOCAL_LIB_ROOT="/home/perl_ss/perl5" PERL_MB_OPT="--install_base /home/perl_ss/perl5" PERL_MM_OPT="INSTALL_BASE=/home/perl_ss/perl5" @INC: /home/perl_ss/perl5/lib/perl5/aix-thread-multi /home/perl_ss/perl5/lib/perl5/aix-thread-multi /home/perl_ss/perl5/lib/perl5 /usr/local/lib/site_perl/5.8.8/aix-thread-multi /usr/local/lib/site_perl/5.8.8 /usr/local/site_perl/common /usr/opt/perl5/lib/site_perl/5.20.1/aix-thread-multi /usr/opt/perl5/lib/site_perl/5.20.1 /usr/opt/perl5/lib/5.20.1/aix-thread-multi /usr/opt/perl5/lib/5.20.1 /usr/opt/perl5/lib/site_perl/5.8.8 /usr/opt/perl5/lib/site_perl
mysql_connect_timeout laughs at me
1 direct reply — Read more / Contribute
by bbarnett
on Jan 18, 2017 at 18:42
    Nothing I do, seems to make mysql_connect_timeout actually function.

    I've read endless posts, via Google and otherwise on the subject. I've appended in many forms, mysql_connect_timeout=1 to my connect line.



    and, I've tried adding port=, tried not using identifiers (eg, just db;;3306;mysql_connect_timeout=1) and about 17 other variations.

    In all of these instances, I can hear the deep, evil laugh of mysql_connect_timeout in the depths of my mind.

    I was going to move on to using some form of timeout, but *then* read about 17.3 thousand posts about "don't do that, you'll get a segfault!', or -- 'use this method with perl 5.x or you will feel extreme pain!'.

    I believe I'm running 5.18 of perl, and it's ubuntu. I'll be able to check more directly when at work tomorrow -- that evil laugh, that never ending laugh kept me distracted, and I did not check versions prior to leaving.

    Any immediate suggestions? Ideas? A "why are you doing that, now I'm laughing too!" thoughts?

    Any help mucho appreciated.


Please help with Regexp::Common
3 direct replies — Read more / Contribute
by scorpio17
on Jan 18, 2017 at 18:26

    I'm trying to teach myself how to use Regexp::Common, and I'm having a little trouble.

    The following works as expected, and finds the number 1234 embedded in the string aaaa1234cccc:

    use strict; use Regexp::Common; while ( my $word = <DATA> ) { chomp $word; if ( $word =~ /$RE{num}{int}/ ) { print "Integer detected: \"$word\"\n"; } else { print "$word\n"; } } __DATA__ aaaabbbbcccc aaaa1234cccc ddddeeeeffff

    However, this does NOT work as I would expect:

    use strict; use Regexp::Common; while ( my $word = <DATA> ) { chomp $word; if ( $word =~ /$RE{profanity}/ ) { print "Profanity detected: \"$word\"\n"; } else { print "$word\n"; } } __DATA__ aaaabbbbcccc aaaaXXXXcccc ddddeeeeffff

    In this case, change XXXX into your favorite 4 letter offensive word. If I change the data string to this: "aaaa XXXX cccc" (i.e., add spaces around the XXXX, then it finds it).

    It seems like the profanity patterns have start of word / end of word anchors built into the patterns, and thus don't work if the word is embedded inside another string? Is there any way to control this behavior? I've gone through the docs, but so far I can't find a way.

    I'm using perl 5.14 (activestate) on Win7. Thanks for any push in the right direction.

Common module lib across Perl versions on same system
3 direct replies — Read more / Contribute
by VinsWorldcom
on Jan 18, 2017 at 15:45

    I've done a bit of searching, but I'm not getting the right results so thought I'd pose the question here.

    I use Strawberry Perl on Windows and have a few different versions installed (5.8, 5.14, 5.18 32/64, 5.22). I manage them with a simple batch script that changes a directory junction from C:\strawberry to the appropriate Perl. Works great.

    HOWEVER, when I switch from one to another, I "lose" all my modules - as expected. In other words, when I CPAN install a non-core modules to version 5.14 for example, when I switch to version 5.18, it isn't there - no shocker. ...

    But could it be?

    For some pure-perl modules, there should be *no* issue providing there are no backward-compatibility, new feature enhancements used. It'd save a bunch a time installing the same module 5 times for each of my 5 versions. I do have a %USERPROFILE%\perl directory and 'set PERL5LIB=%USERPROFILE%\perl\lib' in Command Prompt environment variables.

    But are there implications? I'd install in 1 version of Perl so that CPAN database gets updated, but the other 4 wouldn't - what craziness could ensue? Has anyone done this or is there a better way that I'm missing? My searching keeps turning up local::lib - which is bundled in vendor/lib with Strawberry, but this sounds like what I'm already doing with PERL5LIB.

    UPDATE: So I tried it - created a %USERPROFLE%\perl and %USERPROFLE%\perl5 directories. %USERPROFLE%\perl5 is a symlink (mklink in Windows) to a subdirectory in %USERPROFLE%\perl:

    VinsWorldcom@C:\Users\VinsWorldcom> ls perl Directory of C:\Users\VinsWorldcom\perl [.] [bin] [..] CommonConfig.pm [5.08.8-MSWin32-x86-multi-thread] [lib] [5.18.1-MSWin32-x64-multi-thread] MyConfig.pm [5.18.2-MSWin32-x86-multi-thread] [5.22.2-MSWin32-x64-multi-thread] 2 File(s) 7,449 bytes VinsWorldcom@C:\Users\VinsWorldcom> ls -al [...] 01/19/2017 07:52 AM <JUNCTION> perl5 [C:\Users\VinsWorldcom\pe +rl\5.18.1-MSWin32-x64-multi-thread]

    I set PERL5LIB:

    PERL5LIB=C:\Users\VinsWorldcom\perl5\lib;C:\Users\VinsWorldcom\perl\li +b

    Now for common pure Perl modules I want to share across all versions and I know will work on all versions, I install with:

    cpan -j C:\Users\VinsWorldcom\perl\CommonConfig.pm Module::Name

    ... and it gets installed to %USERPROFILE%\perl, which has the ..\perl\bin in my %PATH%. Tested and it works fine.

    Not sure of the future implications of this or if it's really the way to go. I don't use Perl all that often, but I do maintain a few modules and like to have different Perl version to test them on. Now instead of installing multiple copies of the same module into different Perl site directories, I install it once in a common place and all Perls can run against it and test. Limited use case, just wondered how other developers more experienced than I would handle something like this.

Feature Idea: qr//e (updated with solutions)
4 direct replies — Read more / Contribute
by haukex
on Jan 18, 2017 at 08:47

    Dear Monks,

    As I was thinking about this node about dynamically building regexes, I had the idle thought that it might be nice if qr// supported qr//e, analogous to s///e it would eval the inside of the construct before parsing it as a regex. Now this is really just a very minor itch, and I don't yet have any idea of how much sense it makes or how difficult it might be to implement, but I still thought I'd bounce it off of you.

    Thoughts? Maybe the "normal" and/or "hacked" solutions below are good enough, and the effort required to implement qr//e isn't worth it? Other potential problems I haven't noticed yet?

    Update 2017-01-19: TIMTOWTDI has already provided plenty of possible solutions, and I just wasn't feeling creative enough at the moment to see them :-) Thank you very much, LanX, Haarg, and vr! I updated the code with your solutions, and added Test::More and sub testre.


    -- Hauke D

ActiveState new vs old?
3 direct replies — Read more / Contribute
by enrgyxprt
on Jan 18, 2017 at 07:59
    Its been a while since I installed ActiveState perl, perl -V shows I have V5 something... So I updated all using PPM.. Now I am thinking about updating to the newest activestate community version... Any downsides ?
Last service name comes up empty in NMAP Parser
2 direct replies — Read more / Contribute
by Noosrep
on Jan 18, 2017 at 05:53

    I have an XML file that is generated as follows:

    <port protocol="tcp" portid="139"><state state="open" reason="syn-ack" + reason_ttl="64"/><service name="netbios-ssn" method="table" conf="3" +/></port> <port protocol="tcp" portid="445"><state state="open" reason="syn-ack" + reason_ttl="64"/><service name="microsoft-ds" method="table" conf="3 +"/></port> <port protocol="tcp" portid="1984"><state state="open" reason="syn-ack +" reason_ttl="64"/><service name="bigbrother" method="table" conf="3" +/></port>

    With following code, I parse it:

    my $fct_openPort = (join ',',$fct_host_obj->tcp_ports('open'))."\n" ; my @fct_ports = split ',', $fct_openPort; for my $fct_port (@fct_ports) { my $fct_svc = $fct_host_obj->tcp_service($fct_port); my $fct_service = $fct_svc->name() ; print "\nservice : $fct_service \n" ; print "port : $fct_port \n" ; print "service and port = $fct_port:$fct_service \n" ; }

    However, the last open port has no service!

    service : netbios-ssn port : 139 service and port = 139:netbios-ssn service : microsoft-ds port : 445 service and port = 445:microsoft-ds service : port : 1984 service and port = 1984 :

    Does anybody have any why the last service isn't resolved? When I change

    my $fct_svc = $fct_host_obj->tcp_service($fct_port);


    my $fct_svc = $fct_host_obj->tcp_service("1984");

    it does work

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.