Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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
Module Ideas, Suggestions, and Requests
4 direct replies — Read more / Contribute
by oducs
on Jun 19, 2018 at 08:34

    I am looking for new and interesting ideas for Perl modules!

    The chosen modules will be uploaded to the new oducs CPAN:

    If you have a module which you would like to abandon into my care, let's hear about it.

    Also, I have an interest in simultaneously developing Pure-Perl and XS versions.

    Appreciated, Charlie Root (
Benchmarks target in Makefile
2 direct replies — Read more / Contribute
by bliako
on Jun 19, 2018 at 07:50

    Dear Monks,

    I would like to add a target for running benchmarks on my code to the Makefile produced by ExtUtils::MakeMaker

    I already have a file which does everything and prints a report. I would like to have it executed whenever I do: make benchmarks . And only then because it is time consuming and should not be in tests.

Win32::OLE SaveAs Unicode
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jun 19, 2018 at 07:39


    I need to use Win32::OLE to extract the text from MsWord. The best solution I could find to maintain a bit of formatting is to use the SaveAs function (I would prefer to read directly into a variable, but I can leave with it). The problem is I can NOT find how to set the parameters to save the file in Unicode (something you get asked by Word after clicking on SaveAs...). I've read all I could, but could not find any substitution/completion of "wdFormatTextLineBreaks" to achieve this goal. On Microsoft specification page, they speak about "wdFormatUnicodeText" with value "7". But I can't find how to specify it in my script (just replacing "wdFormatTextLineBreaks" with "wdFormatUnicodeText" does not produce any effect). Maybe some of you know the answer.

    #!/usr/bin/perl use strict; use warnings; use File::Spec::Functions qw( catfile ); use Cwd qw(cwd); use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; $Win32::OLE::Warn = 3; my $dir = cwd; my $word = get_word(); $word->{Visible} = 0; my $doc = $word->{Documents}->Open(catfile $dir, 'test.docx'); $doc->SaveAs( catfile($dir, 'test.txt'), wdFormatTextLineBreaks ); $doc->Close(0); sub get_word { my $word; eval { $word = Win32::OLE->GetActiveObject('Word.Application'); }; die "$@\n" if $@; unless(defined $word) { $word = Win32::OLE->new('Word.Application', sub { $_[0]->Quit +}) or die "Oops, cannot start Word: ", Win32::OLE->LastError, "\n"; } return $word; } __END__
How can I replace the pattern in the 6 th field?
2 direct replies — Read more / Contribute
by theravadamonk
on Jun 18, 2018 at 11:23

    Hi Perl Monks,

    I have DATA like this

    __DATA__ Jun 12 09 mail ( - ( 0.075 9387 Jun 12 10 mail ( - (,(recip2@domai -1.889 25623

    How can I replace the pattern ( and ) in the 6 th field?

    The OUTPUT I expect is

    __DATA__ Jun 12 09 mail ( - 0.075 9387 Jun 12 10 mail ( -,recip2@domain.c +om -1.889 25623

    the below code replaces all fields.

    $_ =~ s/\(|\)//g;

    Can I have something like this?

    $_ =~ s/\(|\)//$f[6]g;

    Your Ideas? Pls help me to slove this.

Combining "Reverse Ajax" aka "Comet" with Mojolicious?
No replies — Read more | Post response
by LanX
on Jun 18, 2018 at 09:12
    We use a "XMLHttpRequest long polling" approach at work to dynamically push JS and HTML actions via Ajax from the server to the browser, thus reducing the amount of JS coded and keeping application logic on the server side.

    I'd like to migrate to Mojolicious, and would prefer to hear of ready to use plugins before reinventing the wheel... :)

    Any recommendations?

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Algorithm inspiration required.
13 direct replies — Read more / Contribute
by BrowserUk
on Jun 18, 2018 at 07:16

    I'm looking to detect a repeating sequence in a stream of data.

    That is, given an essentially endless source of data that is known to eventually repeat; detect the start and length of the repeating sequence.

    In simplistic terms, I want to program the equivalent of the algorithm that solve this regex: $str =~ m[(.+).*?(\1)]g;

    Except that the values aren't characters or anything easily translated to characters and I cannot see the entire stream at any given time.

    And the data stream and the length of the repeated sequence can be big. Very big. Likely bigger than I can hold in memory, so all of those Liv-Zempel windowed and sliding buffer compression algorithms go out of the window; as do any complex tree structures (trees/tries/graphs et. al).

    The thought in my mind at the moment is (an adaption of) the rolling checksum algorithm used by rsync; but I'm not seeing how to apply it to my problem.

    Any thoughts on that; or any pointers to any other algorithms that might be adaptable to this problem gratefully received.

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit
PAR pp macOs set -mmacosx-version-min
1 direct reply — Read more / Contribute
by IB2017
on Jun 18, 2018 at 06:52

    Dear monks

    I am creating a binary of my script for macOS using PAR pp (latest version). Is there a way to set the value of -mmacosx-version-min? Reason: pp seems to set it automatically to the OS version used to compile the binary. In this way, however, there are problems when running the same binary on older OS versions. The binary created with pp contains the following info (read with  $ otool -l binary):

    Load command 9 cmd LC_VERSION_MIN_MACOSX cmdsize 16 version 10.13 sdk 10.13

    In some circumstances (for example if the binary is bundled in a .app), macOS will refuse to run the binary if the OS is older than the version indicated here (at least this is what I 've understood with my researches until now). The pp instructions do not seem to mention any option.

CPAN PAUSE Accounts for Organisations
1 direct reply — Read more / Contribute
by kcott
on Jun 17, 2018 at 19:44

    The company I work for is considering putting some of its non-commercially-sensitive Perl modules on CPAN for general use. I have been asked to investigate this.

    I already know about PAUSE and how to "Request PAUSE account" (I have such an account myself). The wisdom I'm seeking in this instance regards accounts for (commercial) organisations and whether there are any special considerations.

    It looks like the process should be straightforward; but, of course, looks can be deceptive. If anyone has done this previously and encountered any stumbling blocks, gotchas, or such-like, a description of your experiences and how they were overcome (or, indeed, how to avoid them in the first place) would be much appreciated.

    Thanks in advance.

    — Ken

How should I manage CPAN when using two versions of Perl in my computer?
4 direct replies — Read more / Contribute
by hda
on Jun 17, 2018 at 13:16
    Dear monks!

    I normally use two different versions of Perl on my computer: one that comes with the Linux distro (openSUSE) I use and another one that I use to write scripts and mess with, and that I normally compile myself from source. The reason I do this is to not introduce changes in the system's installation and potentially brake things beyond my knowledge on how to repair.

    Until now I have done the quick & dirty procedure of just relying on my (usually more up to date) installation and neglect the system's Perl. However I realize that this is possibly not the soundest strategy. My question then is how should I best manage module installation and update using CPAN in these different installations?

    The CPAN executables live in different folders and (I believe) are compiled to point to different sets of libraries. These executables can be called separately (/usr/bin/cpan; or /usr/local/bin/cpan). Now, CPAN requires a sort of environment (i.e. /root/.cpan/...). Both executables seem to use this same environment, but apparently these two CPAN realize the different upgrading needs (for example when calling "r").

    How does this impact in the update of modules? Should I aim to create different CPAN work directories? Are there any recommendations out there on how to proceed with this?

    Any hint will be appreciated.

    Thanks in advance.

Hobo with a bit of recursion
1 direct reply — Read more / Contribute
by Veltro
on Jun 16, 2018 at 14:31

    Hello everyone,

    I have constructed this piece of code to illustrate three problems and I would like to know: How would you write this code so that it works?

    Problem 1: The join is located at a problematic position due to the nature of how hashes work. Sometimes the code takes 6 seconds to execute and sometimes 2 + 6 seconds.

    Problem 2: L2_counter1 => 3 is not incremented

    Problem 3: (Is actually a question) Why do I need to use a share? The data is incremented independently, so I would think there should be no problems regards synchronicity. However if I don't use the share, nothing gets incremented at all...

    Here is the code:

    use strict ; use warnings ; use MCE::Hobo ; use MCE::Shared ; use Data::Dumper ; sub task1 { print "Starting task 1 for $_[0]\n" ; sleep(2) ; print "Finished task 1 for $_[0]\n" ; } sub task2 { print "Starting task 2 for $_[0]\n" ; sleep(4) ; print "Finished task 2 for $_[0]\n" ; } sub task3 { print "Starting task 3 for $_[0]\n" ; sleep(6) ; print "Finished task 3 for $_[0]\n" ; } MCE::Hobo->init( max_workers => 2, # hobo_timeout => 10, # posix_exit => 1, ) ; my $mutex = MCE::Mutex->new; my $_test = { L1_counter1 => 1, # L1_counter2 => 2, # L1_counter3 => 3, nested1 => { L2_counter1 => 3, # L2_counter2 => 2, # L2_counter3 => 1, }, } ; my $test ; tie %{$test}, 'MCE::Shared', { module => 'MCE::Shared::Hash' }, %{$_te +st} ; print Dumper( $test ) ; sub executeTasks { my $in = $_[0] ; my $hobo ; foreach( keys %{$in} ) { if ( ref $in->{ $_ } eq 'HASH' ) { executeTasks( $in->{ $_ } ) ; } else { if ( $in->{ $_ } == 1 ) { $hobo = mce_async { task1( $_ ) ; ++$in->{ $_ } ; } ; } elsif ( $in->{ $_ } == 2 ) { $hobo = mce_async { task2( $_ ) ; ++$in->{ $_ } ; } ; } elsif ( $in->{ $_ } == 3 ) { $hobo = mce_async { task3( $_ ) ; ++$in->{ $_ } ; } ; } ; } ; } ; $hobo->join() ; } ; executeTasks( $test ) ; print "\n" ; print Dumper( $test ) ;
dbi: moving big data among databases (prepared statements)
5 direct replies — Read more / Contribute
by leostereo
on Jun 16, 2018 at 13:43

    Hi guys , I need to move big databa among databases. I have been reading about improving performance with mysql prepared statements. So far I dont understand why it is better neither how to use it.
    Lets suppose I have the following "bring and insert data" procedure:

    #!/usr/bin/perl use strict; use warnings; require DBI; ### #variables here my @big_data_array; ### foreach $id (@big_data_array){ $query1 = "SELECT * from database1.table WHERE id = '$ +id' my $sth1 = $dbh1->prepare($query1); $sth2->execute(); while (my @row = $sth1->fetchrow_array ) { $val1 = $row[0]; $val2=$row[1]; } $query2 = "insert into database2.table ('value1','valu +e2')". " VALUES('$val1','$val2')"; my $sth2 = $dbh2->prepare($query2); $sth2->execute(); }

    Question is how to achieve same result using prepared statements ?
    And why is it better ?
    I will try to find more info about it. Regards, Leo.

Possible scoping issue with Log::Log4perl logger
3 direct replies — Read more / Contribute
by talexb
on Jun 15, 2018 at 17:52

    I hope this isn't a stupid question, but at least I've discovered the solution to my problem, and I'm happy to share this story in the event that it helps someone else.

    I've developed a pile of scripts that use Log::Log4perl, a module that I love to bits. Wanting to implement a system that would E-Mail me when there was a problem, I decided to add an E-Mail appender to my configuration. It worked fine in my test scripts, but didn't work in my work scripts, and I couldn't understand why.

    I finally figured it out this afternoon (which will explain why I'm pausing to sip from my tall can of Waterloo Amber "Ontario's First Craft Brewery"). My test script looks like this:

    { Log::Log4perl->init ( $log4perl_config ); my $log = Log::Log4perl->get_logger(); .. $log->info('Some stuff'); }
    This works fine. My work scripts are bigger and have subroutines in which I want to do logging, so they look like this:
    my $log; { Log::Log4perl->init ( $log4perl_config ); $log = Log::Log4perl->get_logger(); .. $log->info('Some stuff'); do_something(); } sub do_something { $log->info('Some other stuff'); .. }

    See the difference? I'm using what I call a file scoped variable in the work script so that I don't have to pass the logger into the subroutine (something MSCHILLI goes 'Brrrr!' to here). I believe Log::Log4perl collects log entries to go out by E-Mail until the logger goes out of scope.

    So the test script works fine. The work script's logger (I thought) would also go out of scope and send the E-Mail when the script finishes -- but no E-Mail is sent. Why not?

    Anyway, my workaround is going to be to call get_logger in whichever scope I need to do logging. This works fine, but I'm left wondering why doesn't Log::Log4perl see that the logger has gone out of scope in the work script and send the E-Mail? Is there a 'finalize' or 'terminate' method I could have called to trigger this? Is this an error in the behaviour? (I find that hard to believe, for a module that's been around since 2002).

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

New Cool Uses for Perl
Why is it so easy to make Perl apps for Apple Mac?
2 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 17, 2018 at 13:40
    Compile your Perl to a portable binary application for Apple Mac (99k):
    echo 'display alert (do shell script "perl -v")' | osacompile -o perl. +app
    Write apps for Apple Mac in Perl: Pt.1, Pt.2, Pt.3
How to write apps for macOS/OSX in Perl! Part 2
No replies — Read more | Post response
by Anonymous Monk
on Jun 14, 2018 at 17:00
    Welcome to Part 2 of How to write apps for macOS/OSX in Perl! See Part 1 to get started with the built-in macOS devtool Automator. This edition demonstrates how to:

    • Process choices with Perl from an Applescript dialog to:
      1. Display output from Perl to an Applescript dialog.
      2. Execute Perl in Terminal to display its output.
      3. Send output from Perl to an application (TextExit).
    Applescript is to the operating system what Javascript is the the web browser. It can do many things and what it can't do can always be handled by shell commands and especially Perl! When the code below is saved by Automator as something like you will have a 1.3MB portable binary application! Double click and ENJOY!
    • Other techniques covered here include:
      1. Visiting websites (Perlmonks of course!)
      2. Displaying notifications
      3. Application control
      4. Applescript subroutines
      5. Abusing buttons to widen dialogs
      6. How to rule your world with Perl!
    (* Demonstration macOS/OSX app in AppleScript and Perl *) (* Posted to by Anonymous Monk 6/14/2018 *) (* Node: How to write apps for macOS/OSX in Perl! Part 2 *) set TITLE to "Perl Version Tool" set PROMPT to "Make a selection" set _1 to "Perl version, patchlevel and license" set _2 to "Perl configuration summary" set _3 to "Perl command line help" set _4 to "Visit!" repeat set what to choose from list {_1, _2, _3, _4} with title TITLE wit +h prompt PROMPT OK button name {"View"} cancel button name {"Exit"} d +efault items _1 set what to what as string if what is _1 then set CMD to "perl -v" # ONE LINERS OR PROGRAMS OF ANY SIZE! else if what is _2 then set CMD to "perl -V" else if what is _3 then set CMD to "perl -h" else if what is _4 then display notification "Opening The Monastery Gates!" set CMD to "open" else if what is "false" then return # EXIT end if if what is _2 then # SEND PERL CODE TO TERMINAL AND EXECUTE doShell(CMD) else if what is _3 then # CAPTURE PERL STDOUT set CMD to do shell script CMD # SEND PERL STDOUT TO TEXTEDIT textEdit(CMD) else # CAPTURE PERL STDOUT set RES to do shell script CMD # MAKE DIALOG WIDE set SPC to " + " # PRINT PERL STDOUT TO APPLESCRIPT ALERT display alert TITLE message RES buttons {SPC & "Cool" & SPC} d +efault button 1 end if end repeat # APPLESCRIPT SUBS: on doShell(CMD) try tell application "Terminal" activate tell application "System Events" to keystroke "n" using {c +ommand down} end tell tell application "System Events" tell application process "Terminal" set frontmost to true keystroke CMD keystroke return end tell end tell on error oops display alert oops as critical end try end doShell on textEdit(CMD) try tell application "TextEdit" activate tell application "System Events" to keystroke "n" using {c +ommand down} end tell tell application "System Events" tell application process "TextEdit" set frontmost to true keystroke CMD end tell end tell on error oops display alert oops as critical end try end textEdit
Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2018-06-19 23:40 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.