Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

The Monastery Gates

( #131=superdoc: print w/replies, xml ) Need Help??

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
Sane deprecation policy for a CPAN module?
4 direct replies — Read more / Contribute
by Dallaylaen
on Nov 17, 2018 at 05:45

    Hello esteemed monks,

    Say I have a CPAN module and I found out that its behavior is not exactly optimal. So I would like to change it, but there may be users out there! How do I change my module before backward compatibility locks me into my bad decisions? And what modules should I look into that do the right thing (tm)?

    My current policy is to keep old behavior with a deprecated warning for 5 releases (not including the bugfix), but I guess that's not the best I can do.

    Thank you.

With perl5.26 getting undefined symbol: PL_thr_key
2 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 17, 2018 at 03:08

    I am porting STAF based perl services to new perl version. When trying to load threads in thread modules, getting error undefined symbol: PL_thr_key at /opt/ActivePerl-5.26/lib/

    I saw some post which says this occurs if perl is not threaded. However, I have installed threaded perl downloaded from Active State. version is perl 5.26.1

    Any clue to solve this?
Multiple Line Regex Not Working
2 direct replies — Read more / Contribute
by ImJustAFriend
on Nov 15, 2018 at 17:06
    Hello again monks. Now that I have the right log file to code against, I have come across another issue. I have a log formatted like this:
    <13>Nov 15 21:26:00 OamCOMM[365626]: TIMESTAMP=Thu Nov 15 21:26:00 2018 MSGCLS=OAMOPE Title=OAM Create OPERATION Severity=Inform message={username:xxxxxxxx@xxxxxxxxxxxxxxxxxxx; causeDISTINGUISH_NAME=label=x,label=x,;label=x,label=xxxxxxxxxxxxxxx, +label=x,label=xxxx USER_LABEL= ******************* parameters after change =******************* label=xxxxxxxxxxxxx label=xxxxxxxxxxxxxxxxxxxxxxx label=xxxxxxxxxxxxxxxxxxxxxxxxxxxx label=sxxxxxxxxxxxxxxxxxxxxxxxxxxxxx label=xxxxxxxxxxxx ******************* xxxxxxxxxxxx =******************* label=x } Message Id=xxxxxxxx
    For troubleshooting purposes I extracted one "chunk" of the log and put it into a text file t.txt. I then crafted to see if I could get the coding to work without impacting my larger script. Basically, I need to capture everything between "message=" and "Message Id" for this log entry. I am thinking in an array for processing after extraction. I have literally tried 40 different ideas, either my own or found on internet search, and nothing works. Here's my code I'm trying to make work:
    #!/bin/perl use strict; use warnings; use Data::Dumper; my $mlsf = "t.txt"; my @res; open IN, "<", $mlsf or die "IN: $!\n"; while (my $mls = <IN>) { @res = $mls =~ m/^.*message=(.*?)Message Id.*$/gs; } print Dumper (\@res);
    When I execute this script, I get:
    $VAR1 = [];
    Anyone have any ideas?
play mp3 stream (music) portably
2 direct replies — Read more / Contribute
by Discipulus
on Nov 15, 2018 at 06:07
    Hello nuns and monks,

    As you can see in my read an mp3 stream and save tracks using icy-metaint (ICY protocol) i was able to succesfully read an mp3 stream cutting it at icy-mataint occurences and also able to (possibly) skip advertisements.

    Now, and was my original goal, I want to reproduce this stream and I found that all modules I investigated need a file while I have a stream.

    If you take a look at my above mentioned code, I just read froma a socket by chunk and, in the read_stream sub, I get $buf populated with just the music (no metadata) and I pass $buf to the write_stream sub.

    So my original idea was to push all these $buf into something like a big cache and have some other sub shifting such cache and play each chunk..

    Some help on how to implement it? ;=) I'd like a perl solution, portable as much as it is possible (you know I mainly work on win32..): so using external programs as'mpeg123' and similar are not what i'm searching for. Until now I have mumbled the following:

    1 - tempfile)As all modules (and programs too) I investigated, needs to be feed with a file, it will be possible to have a temp file and append to it. It's not a optimal solution: how to know how much of the the neverending file was already played? how to rotate it?

    2 - reproxing) Once i have $buf i can re-stream them using a local server listening on and launch an external program (like vlc or you preferred one) to connect to such stream to play it. This is an overcomplicated solution..

    The only module I found that seems able to play music contained in a variable is SDL::Mixer::Music that can receive data via SDL::RWOps but I was not able to make it to run. Examples in this direction will be appreciated. I suppose SDL has some limitation playing mp3 on windows (missing libraries?) I had success only playing wav files (not varibles with wav inside).

    Form the SDL::Mixer::Music documentation

    use SDL; use SDL::Mixer; use SDL::Mixer::Music; use SDL::RWOps; my $rwops = SDL::RWOps->new_const_mem( $scalar_holding_music ); my $music = SDL::Mixer::Music::load_MUS_RW( $rwops );

    Any help and suggestion will be very much appreciated


    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.
B::Xref buggy?
2 direct replies — Read more / Contribute
by LanX
on Nov 14, 2018 at 19:09

    I'm not sure but it seems like B::Xref is buggy, after running perl -MO=Xref,-r,-d

    with 5.24 Activestate on

    D:\tmp>perl -c syntax OK D:\tmp>more use strict; my $sth; my $lines; while ( my @row = $sth->fetchrow_array ) { #5 print "@row.\n"; #7 push @{$lines},+{status => $row[0]}; #9 }

    I'm getting (main) 2 (lexical) $ sth + intro (main) 2 (lexical) $ lines + intro (main) 7 main $ " + used (main) 7 (lexical) @ row + used (main) 9 (lexical) $ lines + used (main) 9 (lexical) @$ lines + used (main) 9 (lexical) $ sth + used (main) 9 (lexical) $ sth + subused (main) 9 (lexical) @ row + intro

    please note that @row was "intro"-duced in line 5 inside while and "used" in line 7 and 9,

    But the output says used in 7 and introduced in 9, which doesn't really make sense.

    (I'm taking no issues (yet) on the "$ sth subused" line which is reporting the ->fetchrow method call.)

    Reproduced with 5.18 under Ubuntu
    $ cat /tmp/xref.out (main) 2 (lexical) $ sth + intro (main) 3 (lexical) $ lines + intro (main) 7 main $ " + used (main) 7 (lexical) @ row + used (main) 9 (lexical) $ lines + used (main) 9 (lexical) @$ lines + used (main) 9 (lexical) $ sth + used (main) 9 (lexical) $ sth + subused (main) 9 (lexical) @ row + intro

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice


    Added line numbers


    Perl seems to optimise to my ($sth,$lines);', that's why '$lines is reported at line 2 not 3.

Resque worker reserve() finds no jobs
1 direct reply — Read more / Contribute
by 1nickt
on Nov 14, 2018 at 08:32

    Update: The issue turned out to be a failure in mocking, not a problem per se with Resque. I am mocking Redis (the back end) with Test::Mock::Redis, but somehow Resque is using an unmocked Redis instance for the pop() call (well, the lpop() call on Redis) even though it is using the mocked instance for all the other calls including the peek(). I think the cause is something to do with Moo/Moose inheritance and load order, ie my mocking is happening too late. Odd since I don;t believe I am instantiating the Resque object until after Redis is mocked, but anyhow I am ~ 23.75 hours over the don't-be-stuck-for-more-than-15-minutes rule, so I gave up and now am popping the job off the queue by accessing low-level Redis calls. If I ever figure it out I'll post back here.

    Hi all, any Resque users out there? I am using Resque at $work for a job queue and it's mostly working as expected. But I've run into a problem when trying to manually pop a job and process it. The documented way to do that is to use the worker object's reserve() method to get the job, and then process it with work_tick(). But it's not working: no jobs are found. This is really odd since the queue has jobs. I hacked the source for Resque::Worker::reserve() as follows:

    sub reserve { my $self = shift; my $count = 0; warn "RESERVING"; for my $queue ( @{$self->queues} ) { warn "QUEUE $queue"; use Data::Dumper; warn "JOBS " . Dumper [ map { $_->{payload} } $self->resque->p +eek($queue) ]; if ( my $job = $self->resque->pop($queue) ) { warn "JOB $job"; return $job; } warn "NO JOBS!!!"; return if ++$count == @{$self->queues}; } }
    ... and it outputs the jobs from peek() as expected, but does not find any jobs with pop()!
    RESERVING at /.../.perlbrew/libs/perl-5.26.1@dev/lib/perl5/Resque/Work line 175. QUEUE account_provisioning at /.../.perlbrew/libs/perl-5.26.1@dev/lib/ +perl5/Resque/ line 177. JOBS $VAR1 = [ { 'args' => [ ... ], 'start_time' => 1542202068, 'class' => ..., } ]; NO JOBS!!! at /.../.perlbrew/libs/perl-5.26.1@dev/lib/perl5/Resque/Wor line 184.

    Any clues will be gratefully received. Thanks!

    The way forward always starts with a minimal test.
DynaLoader can't resolve multiple Linux shared objects
2 direct replies — Read more / Contribute
by boleary
on Nov 14, 2018 at 08:29

    I have created a module built with SWIG. references 2 other shared objects and which I am including in the auto/LicenseInterface directory.

    I cannot get it to load properly for my end application where I am trying to use ActiveState PerlApp to distribute the code as a pre-packaged Linux .exe file (but it works fine in Windows)

    use strict; use warnings; push @INC,"lib"; require LicenseInterface; print "LicenseInterface got loaded\n";

    Here is the lib directory structure |--lib\ | |--auto\ |--LicenseInterface\ | (added this to try to influence @dl_resolv +e_using) | | |

    Here is the ldd report for the shared objects (without LD_LIBRARY_PATH set)

    [boleary@new-host testLib]$ ldd auto/LicenseInterface/LicenseInterface => (0x00f36000) => not found ****This is the .so that dynaload +er can't resolve*** => not found ###BUT THIS ONE gets resolved!!! => /usr/lib/ (0x00508000) => /lib/ (0x00331000) => /lib/ (0x00ac4000) /lib/ (0x002c3000) => /lib/ (0x00ed9000) [boleary@new-host testLib]$ ldd auto/LicenseInterface/libLicIntfcLib.s +o => (0x0025c000) => not found ****This is the other .so that dynaload +er can't resolve*** => /usr/lib/ (0x00682000) => /lib/ (0x00ce7000) => /lib/ (0x00d40000) /lib/ (0x002c3000) => /lib/ (0x00143000)

    When I use or require, the DynaLoader bootstrap code cannot resolve the (and the (I set PERL_DL_DEBUG to 1 before running to get more info) loaded (/opt/ActivePerl-5.18/site/lib /opt/ActivePerl-5. +18/lib . lib, /lib /usr/lib /usr/local/lib) DynaLoader::bootstrap for LicenseInterface (auto/LicenseInterface/Lice Can't load './auto/LicenseInterface/' for module Li +censeInterface: cannot open shared object file: No + such file or directory at /opt/ActivePerl-5.18/lib/ lin +e 191.

    I can easily fix the problem if I add the hard path: "auto/LicenseInterface" to the LD_LIBRARY_PATH in the env I am running perl from

    export LD_LIBRARY_PATH=./auto/LicenseInterface [boleary@new-host testLib]$ perl loaded (/opt/ActivePerl-5.18/site/lib /opt/ActivePerl-5. +18/lib . lib, /lib /usr/lib /usr/local/lib ./auto/LicenseInterface) DynaLoader::bootstrap for LicenseInterface (auto/LicenseInterface/Lice LicenseInterface got loaded

    The trouble with this is that I am using perlapp from ActiveState to try and build and distribute a working .exe file, and I do not have any control over LD_LIBRARY_PATH in that case (and I know that perlApp is no longer supported)

    On a windows system, (where I started this adventure) DynaLoader has no trouble resolving the referenced sharedObjects with LicenseInterface.dll, libLicIntfcLib.dll and llibmgr11.dll and the perlApp .exe file works perectly

    I tried a couple of tricks.. Firt I tried to the ./auto/LicenseInterface to the LD_LIBRARY_PATH inside

    BEGIN { $ENV{LD_LIBRARY_PATH}.="./auto/LicenseInterface"; } use strict; use warnings; push @INC,"lib"; require LicenseInterface; print "LicenseInterface got loaded\n"; exit
    perl loaded (/opt/ActivePerl-5.18/site/lib /opt/ActivePerl-5. +18/lib . lib, /lib /usr/lib /usr/local/lib ./auto/LicenseInterface) DynaLoader::bootstrap for LicenseInterface (auto/LicenseInterface/Lice Can't load './auto/LicenseInterface/' for module Li +censeInterface: cannot open shared object file: No + such file or directory at /opt/ActivePerl-5.18/lib/ lin +e 191. at lib/ line 11. Compilation failed in require at line 8.

    Here you can see that it added ./auto/LicenseInterface to the search path and that status line starting with " loaded (" looks identical to the passing case above, but It still won't load it

    Then I tried adding a file in the ./auto/LicenseInterface directory

    push @dl_resolve_using=dl_findfile( qw( ./auto/LicenseInterface/ ./auto/LicenseInterface/ ) );
    perl loaded (/opt/ActivePerl-5.18/site/lib /opt/ActivePerl-5. +18/lib . lib, /lib /usr/lib /usr/local/lib ./auto/LicenseInterface) DynaLoader::bootstrap for LicenseInterface (auto/LicenseInterface/Lice BS: ./auto/LicenseInterface/ (linux, dl_dlopen.xs) dl_findfile(./auto/LicenseInterface/ ./auto/LicenseIn +terface/ dl_findfile found: ./auto/LicenseInterface/ ./auto/Li +censeInterface/ Can't load './auto/LicenseInterface/' for module Li +censeInterface: cannot open shared object file: No + such file or directory at /opt/ActivePerl-5.18/lib/ lin +e 191. at lib/ line 11. Compilation failed in require at line 8.

    You can see that it actually found the other shared objects, but it still couldn't use them

    It seems that DynaLoader cannot take advantage of the fact that I set LD_LIBRARY_PATH, so when it does its magic it must be limited to using the environment variables from the shell that started it. It is interesting to me that it can resolve the

    Does anyone have any ideas? Are there any known linux modules that are provided with multiple .so files that have worked around this before?

    I can try to create one .so, with the other 2 .so libraries statically linked, but I am having trouble because I don't have total control over the llibmgr11 source.

chr() function
2 direct replies — Read more / Contribute
by catfish1116
on Nov 13, 2018 at 16:51

    I'm trying to figure out the chr() function, and have written a few lines of code:

    #!/usr/bin/perl use v5.12; use warnings; $alpha = chr(65); say "This is what Alpha looks like $alpha". "\n";

    And I'm getting this error

    Global symbol "$alpha" requires explicit package name at ./Page_34 li +ne 5. Global symbol "$alpha" requires explicit package name at ./Page_34 lin +e 6.

    What package is it looking for? TIA catfish

Translate curl to LWP
2 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 13, 2018 at 09:04

    Can you help me translate this Curl command to LWP::UserAgent syntax?

    curl -X POST \ -u "apikey:xxx" \ --header "Content-Type: audio/flac" \ --data-binary @{path_to_file}audio-file.flac \ " +"

    The following doesn't work (obviously, as I do not know - as you can see - how to formulate a similar request with LWP

    my $url=" +ecognize"; my $apikey="xxx"; open($fh, "<", "audio-file.flac") or die "Can't read file: $!"; my $audio = do { local $/; <$fh> }; close($fh); $ua = LWP::UserAgent->new(); $response = $ua->post( $url, apikey => $apikey, Content_Type => 'audio/flac', Content => $audio );
Unable to make shallow copy of Moo hash ref attribute
2 direct replies — Read more / Contribute
by nysus
on Nov 13, 2018 at 00:45

    This is driving me nuts:

    has 'tree' => ( is => 'ro', isa => sub { {} }, default => sub { { '/' => { children => {} } } } + ); has 'clean_tree' => ( is => 'rw', lazy => 1, predicate => 1, ); sub BUILD { my $s = shift; $s->app->add_hook (Dancer2::Core::Hook->new ( name => 'before_template', code => sub { ... if (!$s->has_clean_tree) { my %tree = %{$s->tree}; # Attempting to make shallow copy he +re. $s->clean_tree(\%tree); } # set active my $tree = $s->clean_tree->{'/'}; foreach my $segment (@segments) { $tree->{children}{$segment}{active} = 1; $tree = $tree->{children}{$segment}; } ... } )); }

    $s->clean_tree is reflecting $s->tree despite trying to make a shallow copy of $s->tree first..

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

Perl Mapping (GIS)
4 direct replies — Read more / Contribute
by johnfl68
on Nov 12, 2018 at 22:53


    I looked around, but did not really see any posts of this nature here, so I don't know if anyone here can help. But it doesn't hurt to ask.

    I'm looking for a Perl based mapping (GIS) solution. I need to merge a base map (Natural Earth), and overlay map, and some vector shape files. Nothing too difficult, but may be some different map projections in the merge.

    I see Mapserver, but that doesn't look to be too Perl friendly. Same goes for TillMill. Are there any other Linux (Ubuntu 18.04 server) and Perl friendly options out there that I haven't found yet?

    If anyone has any suggestions, please let me know.

    Thank you as always!

Lincoln Stein's *Networking Programming with Perl* source code
2 direct replies — Read more / Contribute
by ibm1620
on Nov 12, 2018 at 16:47
    This great book, (c) 2001, came with source code that was available at Sadly, the website doesn't seem to be around anymore. Does anyone know where the source code might have moved? Google is providing no leads...
New Cool Uses for Perl
curl2lwp - convert Curl command line arguments to LWP / Mechanize Perl code
1 direct reply — Read more / Contribute
by Corion
on Nov 14, 2018 at 13:07

    After inspiration by Your Mother and some slight hacking, I'm very proud to announce HTTP::Request::FromCurl, together with its companion online site at The module and included curl2lwp program allow you to easily convert curl command lines to Perl code that uses LWP::UserAgent resp. WWW::Mechanize.

    Some code: -X GET -A xpcurl/1.0

    outputs the following code:

    my $ua = WWW::Mechanize->new(); my $r = HTTP::Request->new( 'GET' => '', [ 'Accept' => '*/*', 'Host' => '', 'User-Agent' => 'curl/1.0', ], ); my $res = $ua->request( $r, );

    The online version creates a bit more code, as the output there is likely not consumed by advanced Perl programmers.

    The module parses a subset of the valid curl command lines and generates equivalent code for LWP::UserAgent for it. Support for other HTTP user agents (Mojo::UserAgent, AnyEvent::HTTP, HTTP::Future) is not yet implemented but I welcome contributions there.

    The app driving the online interface is not yet released onto CPAN, but as it is mostly HTML scaffolding and some Javascript, it should be released fairly soon.

Google API Browser
No replies — Read more | Post response
by localshop
on Nov 12, 2018 at 09:42

    As I continue my pilgrimage to becoming passably proficient with Mojo and Google Cloud Services I have been tinkering away with WebService::GoogleAPI::Client and as a working example I was reasonably happy with the ease with which I could produce a basic Google API Explorer that presents the method and parameters of all the Google Discoverable API Endpoints. This is proving a handy starting point to constructing working examples accessing the APIS.

    I plan to extend this to firstly include required scopes, then provide OpenAPI YAML and perhaps ultimately replicate many of the features of Google's API Explorer.

    You can see the Mojo Application running as a Hypnotoad socket served application under CPANEL/WHM hosted environment at

    Today I'm working on the Google Drive API Example available in the Github Repo as a demo of an alternative approach to using a dedicated CPAN module such as the just released Net::Google::Drive

    If anybody has any interesting use cases requiring access to Google Cloud Services let me know. I'm trying to add a new example every few days.

New Obfuscated Code
die if lie! fun with Win32
1 direct reply — Read more / Contribute
by Discipulus
on Nov 12, 2018 at 05:27
    Hello nuns and monks!

    I'm not an obfusctor, but as Win32 is obfuscated per se i present you this little lie/truth game

    use Win32; exit unless @}; $ms = \&Win32::GetSystemMet +rics if $^O; END{ exit if @};while(<DATA>) { s/\s//g ; push @} , jo +in '', map {chr (($^O =~ s/\D+//r)+$_)}( $_ =~ /\d{2}/g ) } seek DA +TA, 0, 0; ; $s.=$_ for<DATA>;die if !eval $s; system('cls'); print $ +^O,' ', map {uc $_} substr($} [4], 0, 1 ), substr ($}[0] , 7 , 1), sub +str( $}[5] ,4,1), substr ($}[8],1,1), $/;} map{die 'lie!' unless($$_[1 +]->($$_[2] )?6:7 )== Win32::MsgBox($}[$$_ [0]] . "?", 4, $0); }[0, $ms +,75], [1, $ms, 91], [2, $ms, 23],[3,$ms, 0x2004], [4,$ms, 67],[5, $ms +,0x2003]; map { print $}[$$_[0]]. "?\n"; <STDIN> eq $$_[1] ( $$_[2] ). +"\n" or die'lie!'}[6,$ms,80],[7,$ms,0], [8,$ms,1]; eval '#!perl' unle +ss $^O; __DATA__ 777 9 8 5 8 36 9 00 7265 830 08 669 82 847 36 765 760 08 7726 +96 976 77 79 858 36 90 0726 5830072798 27390 7978 84 65 76 00 8772 69 +69 76 7 7 7 98583 69 0 0 66 8 58 4847 97 8830 0658 26900 83 876 58080 + 6968 73 8 30 08 4 726 90 080 670 073 78 006 8 79 67 756 96 80 077 796 + 869 74 85 8 3 84006 67 9798 4007378 007 065 7376 1383 6570 69 007779 +6869 89 798 500 808 5840 08 0670 079 78 0 08 37 6 6 58 4 69 0 07 779 6 +869 72798 70077 65788 9007 77 97873 84798283 0068790089798 500726 58 +669 87726584078 3008472690087736884 720079700070738 28384008367 826969 +78 8772658407830084726900726973717 284007970007073 8283840083678269697 +8


    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.
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 scrutinizing the Monastery: (2)
As of 2018-11-18 02:02 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (205 votes). Check out past polls.