Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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
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.


Marshalling Data
2 direct replies — Read more / Contribute
by BillKSmith
on May 21, 2016 at 11:09

    I know that I asked much the same question marshalling data about three years ago. Your answers convinced me that I was not yet ready for this topic. I recently came across my old work and decided to try again.

    The book “Intermediate Perl” ISBN 9781449393090 has a section on marshalling data. In that section, it outlines how to create a pair of arrays each of which contains reference to the other, save these arrays to a file with Data::Dumper, and later, restore them by running eval on the contents of the file. The following code is my attempt to implement and test that example. In order to minimize the number of files in my post, I save the data to a memory file and restore to a separate package in the same script. I have two tests. Each tests that the address portion of one of the references is indeed the address of the other array. The pair of tests is run on the original arrays to validate the tests. The same pair of test is then run on the restored arrays. One of theses tests fails. This convinces me that the arrays are not restored correctly. My question is “why?”. I am not yet interested in any other way to save those arrays. (That is covered later in the same chapter.)

    use strict; use warnings; package main{ use Data::Dumper; our $marshall_data = \do{my $file_simulator}; my @data1 = qw(one won); my @data2 = qw(two too to); push @data2, \@data1; # Add recursive elemen +ts push @data1, \@data2; open my $FH, '>', $marshall_data; print {$FH} Data::Dumper->Dump( # Marshall the data [ \@data1, \@data2 ], [qw(*data1 *data2)] ); close $FH; Testing::recursive_data(\@data1, \@data2); # Both tests pass } package Other{ my @data1; my @data2; open my $FH, '<', $main::marshall_data; my $string = do {local $/ = undef; <$FH>}; # Slurp the string close $FH; # print $string, "\n"; eval $string; # Restore content of a +rrays die "Marshalling Failed: $@\n" if $@; Testing::recursive_data(\@data1, \@data2); # Second test fails } package Testing{ use Scalar::Util qw( refaddr ); use Test::Simple tests => 4; sub recursive_data{ my ($data1_ref, $data2_ref) = @_; ok( refaddr($data1_ref) == refaddr($data2_ref->[3]), '$data2[3] refers to @data1' ); ok( refaddr($data2_ref) == refaddr($data1_ref->[2]), '$data1[2] refers to @data2' ); } }

    Note: Contents of the file are exactly as specified in the book.

    @data1 = ( 'one', 'won', [ 'two', 'too', 'to', \@data1 ] ); @data2 = @{$data1[2]};
Is validation of all subroutine arguments overkill?
6 direct replies — Read more / Contribute
by nysus
on May 21, 2016 at 03:36

    I've been learning test-driven development over the last couple of days. The process has gotten me to become much more careful with my code...but perhaps too careful.

    I was always the type of programmer that rarely validated arguments passed to subroutines. If an argument was passed that was not the expected format, the program would behave unexpectedly or crash and then I'd deal with it. With test-driven development, I'm finding myself writing tests to ensure a subroutine returns the appropriate error message if a passed argument is not what the subroutine expects.

    This is certainly a lot more work. Though I'm sure it makes my code is more robust, I'm wondering at what cost. I'm not writing code for banking institutions or space programs, after all.

    So I'm wondering how other Monks approach argument validation. Is this something you do diligently and is considered to be best practice? Do you think it's worth the time to write tests to ensure subroutines handle bad arguments? Are you using modules like Param::Validate to check subroutine arguments? Any other thoughts on argument validation you'd like to share?

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

Testing private methods a no-no?
3 direct replies — Read more / Contribute
by nysus
on May 20, 2016 at 10:22

    I'm new to testing. I've got a test that uses a call to a private method like so:

    # Check that module loads data my $xyz_events = $checker->_get_event_data('arg'); my $is_hash_ref = ref $xyz_events eq 'HASH'; is $is_hash_ref, 1, 'returns a hash ref';

    I'm thinking it's OK to break the rules a bit since I'm just running tests. It also seems like it makes writing tests easier by testing small components of the module. But I worry it's a sign that I'm going about testing in the wrong way. What is the opinion of the wiser Monks about this?

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

DBI::CSV using a variable to request columns
3 direct replies — Read more / Contribute
by Sandy_Bio_Perl
on May 20, 2016 at 10:21

    Hello Monks. I would like to use a variable "$columns" to describe the columns I wish to extract. Perl will not allow me to store, for example, $column = "sid = $row->{sid}"; because it demands that I declare $row

    I have pasted the troublesome code below. Thank you, in advance for your perls!

    use strict; use warnings; use Text::CSV; use DBI; use Data::Dumper; # Connect to the database, (the directory containing our csv file(s)) my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { f_dir => ".", f_ext => ".csv", f_encoding => "utf-8", RaiseError => 1, }) or die $DBI::errstr; # Output using sql query my $query = (qq(select * from newCsv.csv WHERE gender ='male' AND geno +type ='a' )); # my $columns = "sid = $row->{sid} \tgender = $row->{gender}\n"; # per +l is seeking declaration of $row my $queryResult; my $sth = $dbh->prepare($query); $sth->execute; while (my $row = $sth->fetchrow_hashref) { my $col= "sid = $row->{sid} \tgender = $row->{gender}\n"; # cannot ch +ange this to my $col=$columns $queryResult = $queryResult.$col; } $sth->finish(); $dbh->disconnect(); print "Result \n\n$queryResult";
convert columns into matrix and get population count?
2 direct replies — Read more / Contribute
by fasoli
on May 20, 2016 at 10:05
    Dear Monks,

    I am looking to find a way to convert a 2 column / 100,000 line file into a matrix. In this file, the columns represent X and Y values.

    What I want to get is the following matrix, like so:

    If I have x coordinates x1, x2, x3 and y coordinates y1, y2, y3, I want to get all possible combinations, like x1,y1, x1,y2, x1,y3, x2,y1, x2,y2, x2,y3, x3,y1,vx3,y2, x3,y3 - in the form of a matrix but I can't format it properly for this post :'(

    I also want to get a population, which would be a count of how many times the coordinate (for example) (56,6 , 85,5) occurs and divide this by 100,000.

    A few questions as I don't know how to begin:

    1. the coordinates have 10 decimal points and I'd like to maybe round them up at 2, is there a way to do that before calculating the matrix?

    2. is there a Perl module specifically for matrices? Does this seem like a link that would help me? Also I tried some things from here, specifically I tried this one-liner

    perl -lane '$cnt{$_}++; END { foreach $key (keys %cnt) {print "$key\t$cnt{$key}"} }' input.txt

    do you think it could be doing what I want? I know it's not giving me any population details but I'm not even sure if this code is for combining all coordinates?

    IThe reason why I need this is to be able to plot a heat map later on with gnuplot.

    Also another question for a potential gnuplot/Perl specialist here, is there a way for gnuplot to maybe "interpret" or count the occurrences on its own, without me having a population column or something like that in the file? Maybe if the input coordinates are already in the form of a matrix, gnuplot is able to count them and push this result into a heat map, representing the fractional population of the data?

    I have a feeling that it might be a matter of "simply" having loops going through all entries or something like that? I would appreciate any hints/information as I don't know how to begin, I don't expect you to try and write the code for me but some guidance would be more than welcome.

    Thank you all very much in advance, any information would be greatly appreciated.

portMIDI wrapper for Perl5
2 direct replies — Read more / Contribute
by perltux
on May 20, 2016 at 09:10
    I just found out that somebody has written a Perl6 wrapper for the portMIDI library, see here:
    The original library is here:

    Since I would very much like to be able to use portMIDI with Perl5 I would like to know how hard it would be to port the Perl6 portMIDI wrapper to Perl5.

    I only have average Perl5 programming experience, but have zero experience with Perl6 and have never written wrappers for C libraries (and don't have C/C++ progamming skills).
Help stop brute force
4 direct replies — Read more / Contribute
by Anonymous Monk
on May 20, 2016 at 08:51
    The last four months I have been noticing a large amount of bots trying to brute force wordpress on domains that do not run wordpress.
    They use a very unknown Perl web framework that has a login of its own (with absolutely no brute force protection in any way unless you count captcha), but since the brute force was just for wordpress the Perl system's are left unscathed.

    The first course of action was to ban it from the sites, that was easy. But after a few months of reviewing the logs and finding this IP constantly trying the same thing. Well, that made me a little mad so I started redirecting this IP to a 34 terabyte file. That slowed it's requests to about 8 per day instead of 50 a day.
    When I searched the IP and find out more information. There was a few reports on the reason why they try to brute force wordpress is to hold the website for ransom.

    I don't expect any of your answers to be like mine. How to slow brute force with spam. But by redirecting the IP to another server with a huge file did increase the servers resources that where being attacked.

    Ideally i would like a solution that could slow the brute force requests and reduce the load the attacks have on the servers.
    Could sleep(9000000); work better?
    Could captcha in the login form be reliable enough to stop brute force ?
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// //
New Monk Discussion
Put the formatting information above the posting text box?
3 direct replies — Read more / Contribute
by stevieb
on May 20, 2016 at 19:02

    I'm thinking primarily for SoPW (but I assume a change would affect all posting pages), does anyone think that it would have a positive effect if we had the formatting information (it's rather brief relative to having to scroll to the bottom of the page anyway) *above* the text box?

    I'm not really a statistical type person so this isn't a request for action, but a request for feedback.

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 making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2016-05-24 17:37 GMT
Find Nodes?
    Voting Booth?