Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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
Log::Log4perl::Layout::PatternLayout: setting combined length for two fields?
1 direct reply — Read more / Contribute
by toomas
on May 27, 2016 at 23:03


    Recently I discovered Log::Log4perl. This is such a great piece of work that after a week of using it I'm almost wondering how could I live without it before. But there are things about it I have not been able to figure out by studying the documentation.

    Here is my problem:

    I want to indent log messages by stack depth (for tracing program execution), and although Log::Log4perl itself does not directly support this, I have managed (with help from the Internet, including Perl Monks) to have it my way — almost. I added the following lines to log4perl.conf:

    log4perl.PatternLayout.cspec.S = sub { return ' ' x level_for_l4p() +; } log4perl.appender.std.layout.ConversionPattern = %-27F %3L %S%m%n

    and defined level_for_l4p() in my main program:

    my $zerolevel = 8; sub level_for_l4p { my $level = 0; 1 while caller( $level++ ); return ( $level - $zerolevel ); } Log::Log4perl::init( 'log4perl.conf' );

    (Appropriate numbers for $zerolevel and %F are easily found by trial and error.)

    Logs produced by this setup look basically like this:

    /My/Project/One/ 12 sub0: calling sub1 /My/Project/Another/ 96 sub1: entering /My/Project/Another/ 105 sub1: calling sub2 /My/Project/ 72 sub2: entering /My/Project/ 84 sub2: leaving /My/Project/Another/ 108 sub1: continuing after sub2 /My/Project/Another/ 115 sub1: leaving /My/Project/One/ 16 sub0: continuing after sub1 # etc.

    In principle, this is exactly what I want, but I don't like the appearance of the output: IMHO it fails miserably to please the eye.

    I'd much prefer being able to have the log output look like this:

    /My/Project/One/ sub0: calling sub1 /My/Project/Another/ sub1: entering /My/Project/Another/ sub1: calling sub2 /My/Project/ sub2: entering /My/Project/ sub2: leaving /My/Project/Another/ sub1: continuing after sub2 /My/Project/Another/ sub1: leaving /My/Project/One/ sub0: continuing after sub1

    which would also have the additional benefit of working right out of the box with Emacs' default compilation-error-regexp-alist. To achieve this, it should be possible to say something like %-32{%F:%L:}, i.e. to tell Log::Log4perl to set the total length for %F:%L: as a unit. But I have not been able to find a way to express my intention.

    Is it possible to do what I want? In case I'm missing something obvious, can anybody point me to an existing and/or simple solution?

    I am using Log::Log4perl 1.47 and Perl 5.20.0.


Recovery of a "multi-perl" installation
1 direct reply — Read more / Contribute
by haricot-48
on May 27, 2016 at 10:14

    Hi Monks,
    while doing the initial setup of a server (that will host a web application) I've found something unexpected and I need your help to proceed with my job.
    The installation of a new perl module (DBD::Oracle) gave me this output message:

    Multiple copies of Driver.xst found in: /usr/local/lib/x86_64-linux-gnu/perl/5.22.1/auto/DBI/ /usr/lib/x86_64-linux-gnu/perl5/5.22/auto/DBI/ at Makefile.PL line 39. Using DBI 1.636 (for perl 5.022001 on x86_64-linux-gnu-thread-multi) installed in /usr/local/lib/x86_64-linux-gnu/perl/5.22.1/auto/DBI/

    I've searched and I found that the server seems to have two different "Perl installations" (forgive me if I'm not using the proper term)

    Here follows an excerpt of the content of the two paths:

    root@xyz# ll /usr/lib/x86_64-linux-gnu/perl5/5.22/auto/ total 44 drwxr-xr-x 11 root root 4096 May 27 09:48 ./ drwxr-xr-x 13 root root 4096 May 27 09:48 ../ drwxr-xr-x 3 root root 4096 May 13 16:19 Algorithm/ drwxr-xr-x 2 root root 4096 May 27 09:46 DBI/ drwxr-xr-x 2 root root 4096 May 9 16:48 FCGI/ drwxr-xr-x 3 root root 4096 May 13 16:19 File/ drwxr-xr-x 3 root root 4096 May 9 16:48 HTML/ drwxr-xr-x 2 root root 4096 May 9 16:47 LibAppArmor/ drwxr-xr-x 3 root root 4096 May 9 16:43 Locale/ drwxr-xr-x 4 root root 4096 May 9 16:43 Text/ drwxr-xr-x 3 root root 4096 May 27 09:48 YAML/ root@xyz# ll /usr/local/lib/x86_64-linux-gnu/perl/5.22.1/auto/ total 16 drwxrwxr-x 4 root root 4096 May 27 11:28 ./ drwxrwxr-x 7 root root 4096 May 27 08:19 ../ drwxrwxr-x 3 root root 4096 May 27 11:28 DBD/ drwxrwxr-x 2 root root 4096 May 27 08:19 DBI/

    I don't want to have different installation on the server and, most of all, I don't want the new modules to be installed in the /usr/local/lib/ path, as it seems to be happening to the DBD::Oracle module.
    I've found many posts/answers that explain how different (and coexistent) perl installations can be created; none of them tells how they can be deleted.
    I would like to know if there is a procedure to recovery the main perl installation and roll back to a single "instance".
    Will there be side effects if I delete all the content of the /usr/local/lib/ installation?

    Thank you very much in advance.

X Error in Tk remote drag and drop
1 direct reply — Read more / Contribute
by prenaud
on May 27, 2016 at 08:10


    I use PERL on Linux Mint and I have an error when I drop a file from the Cinnamon desktop on a Tk widget :

    X Error of failed request: BadWindow (invalid Window parameter) Major opcode of failed request: 25 (X_SendEvent) Resource id in failed request: 0x2fd00fd Serial number of failed request: 164 Current serial number in output stream: 165

    My source code is:

    #!/usr/bin/perl use strict; use Tk; use Tk::DropSite; my $mw = new MainWindow(-width => 500, -height => 300); my $label = $mw->Label()->pack->place(-relwidth => 1.0, -relheight => +1.0); $label->DropSite(-droptypes => ['XDND'], -dropcommand => [\&dropFile, +$label]); MainLoop; sub dropFile { print "DROP\n"; }

    What is wrong in this code ?

    Perl version is 5.18.2 and Tk version is 804.033

    Thanks for the help.

Using .pod as a standalone file rather than in .pm and it showing up in MetaCPAN
2 direct replies — Read more / Contribute
by rockyb
on May 26, 2016 at 19:00

    I'd prefer to have some documentation associated with a Perl Module, but I would rather not put it inside the code or .pm file but rather its own .pod file.

    The reason I'd like to do this is so that it can be shared in say a github wiki where folks can interactively edit.

    Before a release though, I'd copy the wiki into the distribution.

    So what are practices or best practices for having documentation showing up on or outside of the code?

hash question
4 direct replies — Read more / Contribute
by duyet
on May 26, 2016 at 06:46
    I've been working with hash for a while now, but there is something i really don't understand.
    my $hash = {}; do_something( $hash ); print Dumper( $hash ); sub do_something { my $hash = shift; $hash = { a => 'alpha', b => 'beta', }; print Dumper( $hash ); }
    when exectuted:
    { 'a' => 'alpha', 'b' => 'beta' } {}
    but if using:
    do_something_else( $hash ); print Dumper( $hash ); sub do_something_else { my $hash = shift; $hash->{g} = 'gamma'; $hash->{d} = 'delta'; print Dumper( $hash ); }
    it shows:
    { 'd' => 'delta', 'g' => 'gamma' } { 'd' => 'delta', 'g' => 'gamma' }
    To me the initialization of $hash is the same in both subs, but apparently it is not. It's probably something very trivial, but i just miss it. Would you please explain why? TIA.
Code coverage of forked code
1 direct reply — Read more / Contribute
by britterm
on May 25, 2016 at 11:46
    Hi monks,

    I have a module which forks several times to set up a few workers. I'm using Test::More and Devel::Cover to do unit testing of my code and generate code coverage. I have unit tests that stress the workers, but the coverage report shows that the forked code didn't execute even though it did.

    I considered putting the child code into separate functions that can be tested independently of forking, but the code relies on piped handles to communicate with the parent, which AFAIK do not function without forking (can't write/read to a pipe in the same process). I would have to do a significant amount of coding in my unit tests to attempt to work around this, and I'm looking for a more straightforward solution if there is one.

    Does anyone know how to configure Devel::Cover to detect coverage in the child process when the program forks? Is this even possible? (perhaps with a different coverage tool?)

    Thanks in advance,
Finding file level lexical variables
1 direct reply — Read more / Contribute
by johndeighan
on May 25, 2016 at 11:35
    Our mod_perl application is sometimes running out of memory. So, I want to create a function to track down all variables outside of functions and check their memory usage using Devel::Size. I'm using Package::Stash to find all package variables (declared using 'our'), but now I want to also find all lexical variables (declared with 'my') which are at the file, i.e. top, level in all packages. I know about PadWalker but don't know how to use it - or anything else - to find and get the memory used by these top level lexical variables.
Collaborate on a module
4 direct replies — Read more / Contribute
by ASeekerOfWisdom
on May 24, 2016 at 10:17

    So sometime ago I adopted a module. The original author had not updated this module for a while and When I spoke to him he was glad I was taking this module over. So after some time I fixed it. Now that module is ready for a release to CPAN.

    So my question is how do I release this module on CAPN? Do I ask the author to release it or Do I release it under my pause ID? (I don't want to take the credit form the original author for doing a lot of the foundation work) This is my first time doing something like this so sorry if this sounds stupid.
Progress count for save_content in WWW::Mechanize
2 direct replies — Read more / Contribute
by perlmad
on May 23, 2016 at 09:48

    Hi Folks

    I am using www::mechanize module to download a file from website and i could not find how long it's take to complete so i need a progress amount for downloading status, my code is shown below

    $mech->save_content($filename,":content_cb" => \&callback); sub callback { my( $data, $response, $proto ) = @_; $progress_amount+= length($data); my $size = $response->header('Content-Length'); print floor(($progress_amount/$size)*100),"% downloaded\n"; # +print percent downloaded }

    It is not working

    Any Idea...

[SOLVED]:Upgrading Perl 5.8 program to 5.22
3 direct replies — Read more / Contribute
by $h4X4_|=73}{
on May 23, 2016 at 06:58

    I would like a Perl program I made years ago to run the latest version of Perl 5.22. But the biggest problem I face with this task is the size of the program. The only way I see this happening is if I rebuild the hole framework from scratch under 5.22 while trying to recycle and convert some methods.

    There is no other reason I can see why i need to upgrade other than the fact that the program is stuck at Perl 5.8 and to upgrade to 5.22 would need a major overhaul to the hole framework.

    Are there any advantages of using the latest Perl version that I missed?

    The lesson was... Don't use Exporter in a file you have named "exporter" to keep your variables in scope. But you can use Exporter in a file called "foo" and it will work fine.
Plack/PSGI Application Deployment
3 direct replies — Read more / Contribute
by expandstudios
on May 22, 2016 at 21:45

    Hey guys, I am in the process of porting an old CGI based web app to PSGI.

    I am just seeking some clarification about how to best configure my environment for hot deployment / CI.

    Environment (so far)

    • CentOS 6.7
    • Perlbrew
    • PSGI WebApp
    • Starman
    • Server::Starter (??)

    Here is what I want to be able to do:

    1. Have the server start on boot (CentOS Service possibly?)
    2. Deploy code to host (most likely using whiskey_disk or possibly git hooks)
    3. Gracefully restart server

    Where I am really looking for guidance is how to best configure the server/application on the CentOS machine so that it will start on boot and can easily be managed (start/stop/graceful restart).

    Once I have that in place I can automate my deployment fairly easily using various tools.

    I just can't get my head around how to use Server::Starter properly in this instance.

    Thanks in advance! Russ

Are you using Perl 6 in production?
2 direct replies — Read more / Contribute
by stevieb
on May 22, 2016 at 16:22

    I've dabbled with it here-and-there (the last real tests I've done were about two years ago). Perl 5 is my favourite language, and I now program in Python professionally.

    I dabbled in p6 prior to learning Python, and there are some obvious similarities, but p6 still has a perl-esque feel.

    It's a slow day here, so I thought I'd ask if anyone here is using p6 in any real-world prod situations, and if so, for what.

    As an aside, I'm curious to know how p6 handles external modules. Yes, I can go do homework, but I thought I'd ask in order to get some feedback here so many people can be apprised. It doesn't appear as though the CPAN handles p6 modules.


New Cool Uses for Perl
i2c attached LCD Character Display for a Raspberry Pi
1 direct reply — Read more / Contribute
by anita2R
on May 24, 2016 at 12:28

    I was unable to find a Perl script to make my SainSmart LCD character display with i2c 'backpack' work from my Raspberry Pi.

    Code for using these devices is available mainly for the Arduino. There is also code in C and python, but I could not find a simple working example in Perl. There is a module for an HTBackpackV2 (HiPi::Interface::HTBackpackV2), but I wasn't able to get this working with the SainSmart LCD.

    I found a python script written by Matt Hawkins here: and I used his python script as the basis for my Perl Script - thanks Matt.

    This script only provides basic display functionality and is run by calling it with two parameters, -s a string of text to display and -l the line number to display the text on. Hopefully it will provide both a way for others to get one of these LCD's working as well as provide the basis for more comprehensive implementations. The subroutines writeByte and sendByte are the key ones, together with the initialization sequence in the init subroutine.

    The script must be run as root to set up the i2c object, but drops back to the regular user immediately after - enter your user name and user group in the two variables $user and $group which you will find at lines 39 & 40.

    When called with no text and no line parameter the LCD initialization code is run.

    After the code I have added some explanation about the way the data is transferred from the backpack to the LCD, including the transition from the power-up 8-bit mode to 4-bit mode. It took me some time to get my head round this!

    In addition to -l 1 & -l 2 for the two lines, -l 50 & -l 51 turn the display off and back on. When the display is turned off with -l 50, the data remains in the LCD's DDRAM memory and the previous text will be displayed by -l 51 (a simple flashing display can be implemented)

    If no line number is given, the text is printed on line 1 and overflows to line 2 if required. All existing text is cleared.

    Examples (run as root/sudo):

    Code for a Raspberry Pi with SainSmart 2 line, 16 character LCD display with i2c backpack at 0x3f, attached to the Pi's default i2c pins.

    Mode of operation & initialization

New Obfuscated Code
Having fun with ambiguity
No replies — Read more | Post response
by trizen
on May 23, 2016 at 14:30
    print $$ /0; # a legit division by zero ^....some.....^ ^^ ^....magic....^ |(?{m{(?{(("\[\[ \)\.\\\|\`\]\[\[ \{\[\.\@\/\(\^\. \[\{\;\\\,\[\@\: \?\+\^\)\("=~s{[ \s]}<>rg)^("\+\) \@\@\(\^\*\(\(\/ \[\:\@\/\[\@\;\\ \{\+\^\.\@\{\(\[ \\\@\;\[\"\""=~s <\s>()gr))})},s[ ]<$^R>seexi})|&: ^....hugs....^ ^.....&......^ ^...kisses...^ // //xo//xo//xo//xo//xo//xo//xo// //
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 romping around the Monastery: (4)
As of 2016-05-28 09:24 GMT
Find Nodes?
    Voting Booth?