Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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
What's going on with either constants folding or B::Deparse output in this case?
1 direct reply — Read more / Contribute
by vr
on Feb 25, 2017 at 06:35

    I'm puzzled with this little problem (a fragment is to reproduce it, never mind what it was doing originally):

    C:\>perl -we "sub parse{${$_[0]}=~/\Gfoo/gc or die} parse \('foo') for + 1..2" Died at -e line 1. C:\>perl -we "sub parse{${$_[0]}=~/\Gfoo/gc or die} parse \(''.'foo') +for 1..2" C:\>perl -MO=Deparse -we "sub parse{${$_[0]}=~/\Gfoo/gc or die} parse +\('foo') for 1..2" BEGIN { $^W = 1; } sub parse { die unless ${$_[0];} =~ /\Gfoo/cg; } parse \'foo' foreach (1 .. 2); -e syntax OK C:\>perl -MO=Deparse -we "sub parse{${$_[0]}=~/\Gfoo/gc or die} parse +\(''.'foo') for 1..2" BEGIN { $^W = 1; } sub parse { die unless ${$_[0];} =~ /\Gfoo/cg; } parse \'foo' foreach (1 .. 2); -e syntax OK

    I'd expect, because of constants folding, two fragments of code to behave the same. Also, see B::Deparse output. Yet code runs differently.

Regex: What does ?k: mean?
2 direct replies — Read more / Contribute
by hoppfrosch
on Feb 24, 2017 at 02:39
    Looking through various Regexp::Common submodules, I very often saw the usage of "?k:" within regex definitions:
    # from Regexp::Common::Comment: sub to_eol ($) {"(?k:(?k:$_[0])(?k:[^\\n]*)(?k:\\n))"} # from Regexp::Common::ZIP Monaco => "(?k:980[0-9][0-9])",
    (much more examples could be given)
    Can anybody tell me what's the function of "?k:" within regexes? Haven't found anything enlightening yet.

more elegant way to parse this?
4 direct replies — Read more / Contribute
by morgon
on Feb 23, 2017 at 23:58

    on OpenWrt I try to find out about visible wifi-networks by parsing the output of iw scan.

    This output looks like this:

    BSS <blah blah> SSID: <ssid> <blah blah> BSS <and so on>
    What I am interested in is the set of all ssids, each being contained in a stanza that starts with "BSS" and ends when the next "BSS" is encountered.

    So I parse it like this:

    my $out = qx| sudo iw dev wlan0 scan |; $out .= "\nBSS"; my @chunks = $out =~ /^(BSS.*?)(?=^BSS)/smg; my @essids = map { /SSID: (.*?)$/ms; $1 } @chunks;
    And that works, but it bugs me that I manually add a "synthetic" BSS to the output of iw so I can then use a lookahead in the regex that would also match on the last entry.

    So I wonder: Is there a more elegant way to do this?

    Many thanks!

How do you structure and run module test code?
7 direct replies — Read more / Contribute
by nysus
on Feb 23, 2017 at 08:39

    I'd love to get some general pointers from pros on how to efficiently create tests for modules.

    Using the Module::Starter::PBP module, I notice that the t directory has the following test files by default: 00.load.t,  perlcritic.t,  pod-coverage.t,  pod.t.

    Some of the questions I'm trying to answer are: When should I create a new .t file? How should I group my tests into the different .t files? What's best practice for naming the .t files?

    Also, I'd like to be able to run the tests as efficiently as possible from vim, my tool of choice. Right now, I'm using Damian Conway's vim configuration which has a short cut for running make on a module. It runs all the tests it finds. I imagine this could slow things down quite a bit, however, if I'm just interested in running a few of the test files. How are the pros running individual test files quickly and efficiently with vim?


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

What basic things should I know about versioning modules?
6 direct replies — Read more / Contribute
by nysus
on Feb 23, 2017 at 06:34

    I'd like to get some general guidance on how to properly use versioning for my modules.

    My question is prompted by the Module::Starter::PBP module. It has a starter template here.

    The starter template throws an error on this line: use version; $VERSION = qv('0.0.3');. The error is Global symbol "$VERSION" requires explicit package name (did you forget to declare "my $VERSION"?)

    While I could slap a my in front of it and be on my way, I am wondering if maybe it was purposefully left off. I also don't know how this line might be used by other modules. And should I use "my" or "our?" What does qv do? I can't find it in the perldoc but I do find mention of it here on CPAN. But I never installed that module to my knowledge.

    If someone could point me to a good resource that can help explain the what's, why's, and how's of module versioning, I'd appreciate it. Thanks.

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

Perl modules that I can use for Multithreading
6 direct replies — Read more / Contribute
by elpis
on Feb 22, 2017 at 08:12

    I want to parallelize a code written in Perl. The code loops through multiple files and calls a subroutine for each file. I also need to share some readonly local data-structures with the subroutine.

    sub process_in_parallel { my $readOnlySchema = foo(); foreach my $file (@files) { validate_the_file($file,$readOnlySchema); } }

    I am pretty new to perl programming and hence need a lot of advice here. What are the perl modules that the perl monks can recommend for this scenario?

    I tried some of the following:

    - threads : The problem with this is managing the threads. Is there an efficient thread Manager or thread pool library that can help me with this? I am also not sure if I can share the readOnly object easily.

    -Parallel::ForkManager : The problem with this is that it forks processes rather than threads and is increasing the time of execution in my case.

    Can you please suggest other libraries also?

    I have the same question posted here also :
Perl5 Perl6 forking
6 direct replies — Read more / Contribute
by reverendmred
on Feb 21, 2017 at 21:22
    I'm returning to Perl after an absence of a couple years to pick up a lot of code I left in beta. Now, Perl6 has changed all the rules.

    Languages need to evolve, but when C evolved into different varieties, ultimately, it was called a different language. The same seems to be true of Perl.

    Is there any way to ensure a switch in Perl 6 so you can choose between languages? Once long ago, we used the top of the file to point the script at the executable. Can we have Perl6 provide something like this to preserve legacy code. It would also be nice for CPAN modules to provide a fork so we can keep alive old stable code.

    I know you must now be thinking 'oh my god, you can't have two languages in one application' but actually, you can. When last left Perl behind and returned to it in the early 00s, it had switched from a procedural scripting language to a very fake OO language. I say very fake, because I worked on a bioinformatics project coming from a pure 00 environment and in my nw position I got criticized for crappy perl code and not doing good OO -- which only showed me my colleagues knew nothing about Perls history and had absolutely no idea what OO really was.

    The point is, if you had good OO like Perl5 code, there should be no problem running it alongside new Perl6 code as long as you treat them as separate languages and you have a fork of the legacy CPAN code. What you need to make sure is that the interfaces between your Perl5 and Perl6 code are stable and work. (Of course, I hate to say, but that old bioinformatics project was not good OO and violated every aspect of encapsulation).

    So, is there a way we can fork projects and modules on CPAN? This would be really, really useful.


cgi progressbar
2 direct replies — Read more / Contribute
by bigup401
on Feb 21, 2017 at 07:03

    i have tried to look around the proper way of progressbar in html. bt no good information i have been playing around with progrssbar in commandline bt not in cgi. as they say perl is good for open source bt web apps not easy too much time to take and alot tests

    any idea or simple. i appreciate

    if (execute code){ # execute code to run } while (the code is runing ) { # show the progress .. show the progressbar from 1 } elsif (the code has finished running) { #stop the progressbar at 100% } else (the code has not executed) { # dont let the progressbar to run } print "Content-type: text/html\n\n"; print <<START_HTML; <!DOCTYPE html> <html> <style> #myProgress { width: 100%; background-color: #ddd; } #myBar { width: 1%; height: 30px; background-color: #4CAF50; } </style> <body> <h1>JavaScript Progress Bar</h1> <div id="myProgress"> <div id="myBar"></div> </div> <br> <button onclick="move()">Click Me</button> <script> function move() { var elem = document.getElementById("myBar"); var width = 1; var id = setInterval(frame, 10); function frame() { if (width >= 100) { clearInterval(id); } else { width++; = width + '%'; } } } </script> </body> </html> START_HTML
Solved : decimal to hex in an array
3 direct replies — Read more / Contribute
by t-rex
on Feb 21, 2017 at 05:31

    hello monks,

    I have an array where I need to convert every even index element to hex , I have written a code but the output is not what i expected

    my @a = "1 10 5 345 2 12"; my $indx=1; foreach my $ind (@a) { print "IND = $ind and index = $indx\n"; if ($ind%2==0) { $ind = sprintf("0x%x",$ind); } $indx++; } print "final conversion input array = @a\n";

    actual output : 1 0xa 5 345 0x2 0xc

    expected output : 1 0xa 5 159 2 0xc

    please let me know where I am going wrong ?

    edit : i got my error , just because of same names i made a silly mistake and couldn't see , sorry for the trouble guys

http post
2 direct replies — Read more / Contribute
by bigup401
on Feb 19, 2017 at 09:18

    i got some issue when i execute my code i get this Response Code: 411

    #!/usr/bin/perl use strict; use HTTP::Request::Common qw(POST); use LWP::UserAgent; my $ua = new LWP::UserAgent; my $senderid = "demo"; my $num = "447777777777"; my $sms = "demo"; my $rep = HTTP::Request->new(POST => " +s/send/?apiKey=edftr44456&message=$sms%20HTTP%20API&from=$senderid&to +=$num"); $rep->content_type("application/x-www-form-urlencoded"); $rep->content_type("Content-Type' => 'application/json"); my $repobj = $ua->request($rep); my $repcode = $repobj->code; print 'Response code: ' . $repcode . "\n";
Perl 6 OOP: before and after methods "CLOS style"
7 direct replies — Read more / Contribute
by Anonymous Monk
on Feb 18, 2017 at 18:37

    I'm learning Perl 6 and I'm constantly blown away by amazing Perl 6 features, it's something I experienced only while I was learning a bit of Common Lisp.

    I wish to know if in the Perl 6 MOP there is something similar to CLOS before/around/after methods.

    Also, given that my experience with programming is mainly quick procedural scripts (and, sadly, one big system in classic asp and vb for work) , which books/resources can give me a good grasp of Perl 6 OOP philosophy? For CL I loved the CLOS book by Kleene, but Perl 6 approach seems different (Smalltalk-ish???).

    Thank you very much for your wisdom.

New Meditations
Holy Crap! Programming Well is Hard Work
1 direct reply — Read more / Contribute
by nysus
on Feb 24, 2017 at 12:50

    As a hobbyist programmer and someone fascinated with the world of programming and learning what I can about it, it strikes me more and more just how obsessive to detail good programmers are. That's never been a strong suit of mine, unfortunately. I'm impatient and I often make wrong and bad assumptions that make it tough for me to write solid code. And I think what I like about programming so much–even though it often humbles me by making me feel like a bit of a dunce–is that it forces me to think like an engineer. But I have to work pretty damn hard at it and the process is slow and frequently frustrating.

    In the programming field, there is an extraordinary amount of information to take in, process, and put into practice. It seems the more I learn, the less I feel like I know. I marvel at the programmers to be able to do that and who have a natural knack for it. I'd like nothing better than to spend 15 hours a day lost in code (which I've been doing lately) but it still sometimes feels like I'm pushing a rock up a mountain. I have a few projects I want to write and write well but I end up getting diverted by having to learn some new skill first. Every day there seems to be countless new idioms, tools, and concepts that I need to learn and put into practice.

    But I'm eager for the day when it all just clicks, when I can look at someone else's piece of code and read it like a newspaper and know everything that's going on with it (or at least have a pretty good idea). It's frustrating to go down three dead ends or spend an hour figuring out why your code won't do what you want because of a stupid mental error. I'm guessing most programmers like me have gone through a similar phase where they can write code that gets simple stuff accomplished but aren't good enough to take on a really large or complex project.

    Anyway, just needed to vent. I feel better now. And thanks to the Perlmonks who have helped me on my journey toward my goal of achieving programming excellence. I could not keep pushing on this rock without you.

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

New Monk Discussion
Fine grained "a day ago" or "a week ago"
3 direct replies — Read more / Contribute
by stevieb
on Feb 22, 2017 at 23:27

    Request for new clicky-availability...

    When pointing at the arrows << and <, its a week ago and a day ago respective. We need something more updated than that. I do not have a solution, so this is a throw-out for discussion.

    This is, I suppose, a formal (public) application to become a pmdev, so I may become part of the team that can see what is happening, and potentially be part of new ideas.

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 studying the Monastery: (9)
As of 2017-02-25 17:11 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (366 votes). Check out past polls.