Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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
Open an application from windows registry
2 direct replies — Read more / Contribute
by ElAlx
on Feb 26, 2017 at 09:36
    Hello Monks, I'm writing a script which could automatically open a specific version of programm by using the path in windows registry using Win32::TieRegistry. How can i place a variable into the string so that will work?
    use Win32::TieRegistry (Delimiter => '/'); my $version=2.1; my $mykey = $Registry->{'HKEY_LOCAL_MACHINE/Software/SPS/$version'}; my $mykeyval = $mykey->{'/AppsDir'}; $mykeyval2="$mykeyval"."\\start.exe"; system("$mykeyval2");
    I tried to find something for my problem but with no luck. I would appreciate your help! Thank you!
Testing my tests
1 direct reply — Read more / Contribute
by szabgab
on Feb 26, 2017 at 08:52
    Devel::Cover can easily show if a certain function or expression was executed during the test run, but it cannot tell if there was an assertion checking the validity of the result.

    One could randomly change the code under test (e.g. replace a + by a - ) and run the tests again. If they still pass, we have a problem. The tests do not check that code properly.

    Is there a tool for Perl that would automate this process?

    For further clarification, I'd like to change the source code of the module or application under test and leave my tests unchanged.

Can't get progress bar or main window to update using Tkx
1 direct reply — Read more / Contribute
by Anonymous Monk
on Feb 25, 2017 at 16:41

    Hi monks, I have a main window update question. I have a simple but long script that runs as a subroutine when the user makes some selections in the main window. I'm having an update issue with the progress bar. I tried using fork by I got an error due to an line using SMTP in the subroutine. I'm thinking fork may not be he best solution and that I'm missing something. Here's a stripped down example of my code:

    use strict; use warnings; #use Mozilla::CA; use Tkx; use Tcl::Tk; #set window geometry and options my $mw = Tkx::widget->new("."); $mw->g_wm_minsize(400, 500); $mw->g_wm_title(my $title); my $b; $b = $mw->new_button( -text => "Run", -command => \&run, #); #Tkx::after(500, sub { $mw->g_destroy }); #}, ); $b->g_pack( -padx => 10, -pady => 10, ); #Quit button my $b2; $b2 = $mw->new_button( -text => "Quit", -command => sub { $b2->m_configure( -text => "Quit", ); CORE::exit; Tkx::after(500, sub { $mw->g_destroy }); }, ); $b2->g_pack( -padx => 10, -pady => 10, ); #Table Output Tkx::package_require("Tktable"); $mw = Tkx::widget->new("."); my $t = $mw->new_table( -rows => 5, -cols => 3, ); $t->g_pack; #Progress Bar my $progress = "10"; my $overall_progress_bar = $mw->new_ttk__progressbar( -orient => "horizontal", -mode => "determinate", -length => "100", #-maximum => $file_count, #-value => $progress, -maximum => "400", -value => $progress, ); $overall_progress_bar->g_pack; Tkx::MainLoop(); exit; sub run { #First block of code #define links my $keywordsfile="keywords.txt"; ##a lot more happens here print "Test!!"; }

    I've tried adding to the $progressbar value as well and using Tkx::update(); with no luck. Any guidance for this novice would be greatly appreciate. Another thing that I've seen that I'd like to fix is the main window, when I run on a PC, is unresponsive. I know it's all the same issue. Thank you

What's going on with either constants folding or B::Deparse output in this case?
2 direct replies — 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.

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

    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?

    Thanks!

    $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 : http://stackoverflow.com/questions/42391233/perl-modules-to-use-for-parallel-processing
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.

    thanks
    the.rev

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++; elem.style.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

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?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and a moth chases the moon...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2017-02-26 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (376 votes). Check out past polls.