Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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
Moose::Meta programming and derivative classes
1 direct reply — Read more / Contribute
by JayBonci
on Apr 30, 2017 at 17:58

    Hello kind monks,

    Over at E2 I'm working on rewriting the object model to use Moose. This is slowly trying to change the tires on the car while it's moving. I'm still trying to dig in there, but my problem is that I don't know quite the right question to ask, so I thought I'd start here. This is a simplified example

    Let's say I had a Moose Class like:

    package MyApp::Object; use strict; use Moose; has 'greeting' => ('isa' => 'Str', 'is' => 'ro', 'required' => 1); 1;

    For instance, what I want to do is create have MyApp::Object automatically create a MyApp::Object::Collection object which will contain an array of MyApp::Objects and when I call a parameter against it, it will loop through and call each of the MyApp::Object parameters. Additionally, I want this to be subclassable, so if MyApp::ChildObject comes along, that automatically creates MyApp::ChildObject::Collection. I'm a bit lost in the documentation on Moose::Meta, and am not quite sure what to google to continue. Does anyone have any pointers?


Is ActivePerl repositories go free again?
3 direct replies — Read more / Contribute
by exilepanda
on Apr 30, 2017 at 00:39
    Dear monks,

    Story part 1: Days ago, I was looking for where to download PDK9.5(doesn't matter), and while I stepped in some page under ActiveState(from search result), I saw something alike mentioning ActivePerl will go free in the future. Because I was in a rush, I only glanced the page for few second (and can't find them again as my browser clear history per close)

    Story part 2: Yesterday, I was trying my best luck to install some modules in my very old machine using Perl 5.16 in WinXP, and when I hit on ppm.. I saw the repositories are all updated. I can tell there was something like redirected, 403 sort of before, seem I need a business license to access those repositories, but I could update them again yesterday.

    Can somebody tell if the repositories open for free again (for any perl version)?? Since I involved many machines, so I don't sure maybe I saw those redirect 403 from other machine.

Get url
4 direct replies — Read more / Contribute
by kepler
on Apr 29, 2017 at 17:25


    I'm having some troubles regarding a simple get for an url,

    Even using this script, I get a null result (in several hosts except one, bluehost):
    #!/usr/bin/perl use LWP::Simple; use warnings; print "Content-type: text/html\n\n"; my $url = " +ry/2.5_week.atom"; my $data = get $url; print "$url\n$data";

    Can someone help me out?

    Thanks, Kepler
Videos from LPW 2016?
No replies — Read more | Post response
by LanX
on Apr 29, 2017 at 15:59
HASH value error
2 direct replies — Read more / Contribute
by pdahal
on Apr 29, 2017 at 01:58
    I am a beginner in perl. I need to parse an XML file and store the results into CSV file. The problem I am facing is I am getting the output like "HASH(0x3de3350)" instead of PubMed IDs like "16466327" in CSV file. How can i handle this?
Array of variables
7 direct replies — Read more / Contribute
by Michael W
on Apr 27, 2017 at 11:38
    my @Variables = ( $Map_Request_Date,$Map_Due_Date,$Map_Cutover_Date,$ +Map_Complete_Date,$Map_Approved_Date); foreach $Date_Ref (@Variables) { print $Date_Ref; $Date_Ref =~ s/ +/ /; #When day is a single digit it creates two wh +ite spaces ($Month,$Day,$Year,$Time)= split / /, $Date_Ref,4; my %Months = ( 'Jan' => '01', 'Feb' => '02', 'Mar' => '03', 'Apr' + => '04', 'May' => '05', 'Jun' => '06', 'Jul' => '07', 'Aug' + => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' +=> '12' ); if (length($Day) == 1) {$Day = "0$Day";}#Add 0 to the front of sing +le digit days @Variable[$X]=$Year."-".$Months{$Month} ."-" . $Day ; $X=$X+1; }

    Working on a date issue from sql to html format

    previous only used an array of variables to read from

    this time I want to place the value back into the array of variables

    this line: @Variable$X=$Year."-".$Months{$Month} ."-" . $Day ;

    all the code works until I try to write the new variable back in

Randomly reassign hash keys
6 direct replies — Read more / Contribute
by cormanaz
on Apr 26, 2017 at 12:47
    Good day bros. I would like to create a hash, then randomly reassign the keys (to support a randomization test). I know I can get a shuffled list of keys with
    use List::Util qw(shuffle); ... foreach my $k (shuffle keys %foo) { ... }
    but accessing that would leave the keys associated with the same values. I want to randomly reassign the keys to different values already in the hash. So if the original was
    %hash = ( "a" => 1, "b" => 2, "c" => 3, "d" => 4 };
    I could end up with
    %hash = ( "c" => 1, "d" => 2, "a" => 3, "b" => 4 };

    I can imagine how to do that in an inelegant way, but was wondering if there is an elegant way.

Malformed JSON Error Piwigo
1 direct reply — Read more / Contribute
by kiteboywales
on Apr 26, 2017 at 09:43

    Hi all - I looking for advise regarding the following error

     malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "<br />\n<b>Warning</...") at /usr/share/perl5/ line 171

    Hope you dont mind asking - I get this error when uploading to something called PIWIGO. An online image gallery. The perl script itself is available here

    While images do upload fine I get the above error and then the uploading stops. If I run the script again it can be seen that the image it seemed to fail on did upload and then it moves onto the nexxt image and then again the error pops up again.

    If someone has any ideas that would be great....thanks for any advice

Re-dimensioning an HTML table with Perl ?
12 direct replies — Read more / Contribute
by TheDonald
on Apr 25, 2017 at 13:08
    I'm staring down the abyss of something that I would rather not do manually. So it occurred to me that Perl is probably just the sort of thing for such a random requirement. What I need to do is "re-dimension" (what is the correct word ?) an HTML table. The table is currently 5x12, and I want to turn it into, say, 7x9. The thought of lifting and shifting dozens of cells by hand is filling me with dread ! I've no ideas where to start in terms of automating this, let alone how to code it (I've only recently joined the long road to Perl wisdom !).
"my" declaration problem
6 direct replies — Read more / Contribute
by Hosen1989
on Apr 25, 2017 at 07:17

    Dear ALL,

    I was debug some old dirty script of mine (which without strict nor warnings ^_^), and faced this issue:

    As you can see in case(1), variable $me had been declared more than once, and to output of this script is: []

    #----------[ CASE(1) ]----------# my $v_place = 'home'; my $me = 'moving'; my $me = 'at home' if($v_place =~ m/^home/); my $me = 'at work' if($v_place =~ m/^work/); print "[$me]"; __END__ output: [] #-------------------------------#

    But after correct the declaration problem as in case(2), we got the correct output: [at home].

    #----------[ CASE(2) ]----------# my $v_place = 'home'; my $me = 'moving'; $me = 'at home' if($v_place =~ m/^home/); $me = 'at work' if($v_place =~ m/^work/); print "[$me]"; __END__ output: [at home] #-------------------------------#

    Now,can any monk explain me just what happen here?



'Missing version identifier' error while connecting to Hive, using Thrift module of Perl
1 direct reply — Read more / Contribute
by Omnitrix
on Apr 25, 2017 at 07:03

    I tried to connect to Hive using Thrift::API::HiveClient2. Wrote the following:

    #!usr/bin/perl use strict; use warnings; use Thrift::API::HiveClient2; my $port = 12345; my $host = '123:456:789:987'; my $client = Thrift::API::HiveClient2->new( host => $host , port => $port, ); $client->connect() or die "Failed to connect\n"; my $query = "hive query;"; my $rh = $client->execute($query);

    An I am getting the following error->

    Thrift::TException error: Missing version identifier (code 0) (in cl +eanup) Thrift::TException error: Missing version identifier (code 0) at (eval + 144) line 31.

    My Hive client is HiveClient2. What am I missing?

Debugging Perl Mojolicious application
4 direct replies — Read more / Contribute
by sduggal
on Apr 24, 2017 at 02:58

    Hi Monks!

    I have a Perl Mojolicious framework application/web app on Windows. It is using the development server for now. Does anyone have experience on debugging in such an environment using an IDE? I want to use breakpoints and step through the code. Please guide me on the IDE in case anyone has been in the same boat.

New Meditations
Assigning to Hash Values (updated)
No replies — Read more | Post response
by haukex
on Apr 28, 2017 at 12:49

    The thread "Randomly reassign hash keys" got me thinking about this one. The values doc says:

    Note that the values are not copied, which means modifying them will modify the contents of the hash.

    This means that $_++ for values %hash; will modify the original hash values, and the following (based on this AM post) will assign to the values of the hash:

    sub { @_[0..$#_] = qw/r s t/ }->(values %hash);

    The above work because both the foreach loop variable and the elements of @_ are aliases to the original scalars. The slice in the second example is necessary, since @_ = ... would clobber the array and remove the aliasing, instead of assigning to its elements.

    However, values itself is not lvalue, meaning that values(%hash) = qw/a b c/; won't work. Neither will (values(%hash))[0] = 'a';.

    Here's my "invention", which I present as a curiosity rather than a suggested solution. It makes use of Lvalue subroutines and Prototypes. The parens on the left are necessary for the sub to be called in list context.

    sub lvalues (\%) : lvalue { values %{$_[0]} } (lvalues %hash) = qw/i j k/; # works!

    Since the order of the values returned by values is random, this probably isn't particularly useful other than in the context of the thread I mentioned above:

    (lvalues %hash) = shuffle values %hash;

    Updates 1&2: However, note that repeated calls to (lvalues %hash) = values %hash; will only "randomize" the values once, and on older Perls the order won't be very "random" at all apparently not randomize at all, I would guess because the order of the returned values is not randomized between the calls to values. Some interesting reading on the topic: Re^2: setting PERL_PERTURB_KEYS & PERL_HASH_SEED in a perl file and Re^2: Curious: are anon-hashes in random order?

    Minor updates for clarification.

Big thank you to the Perl community.
2 direct replies — Read more / Contribute
by Anonymous Monk
on Apr 24, 2017 at 06:21

    Revered Monks and dwellers of this venerated place,

    I've been here for approximately two months now and I have no words to express my gratitude. The level of information shared here is amazing. The knowledge of the monks just blows my mind. Answers given here are of very high quality and I've come to realize that PerlMonks is the best place to learn Perl

    Just wanted to take a moment to extend a heartfelt "Thank You" to all you knowledgeable and helpful folks here. Spending a few minutes here is far more enriching and fulfilling. The suggestions and advice given by you Monks has literally shaved off hours of time. I started with Perl due to its practicality and immediacy with which it naturally lends itself to real life problem solving, but now, I have started falling in love with this amazing language, all thanks to you folks.

    This language deserves so much more attention and respect than it gets. All this talk of "Perl is Dead" now simply makes me wonder what the hell is going wrong with folks. This language will never die, because 1) its a pragmatic, practical and amazing language and 2)PerlMonks.

New Cool Uses for Perl
Prima + MCE::Hobo demonstration
2 direct replies — Read more / Contribute
by marioroy
on Apr 29, 2017 at 03:03

    Respected Monks,

    Starting with MCE 1.828 and MCE::Shared 1.825, running MCE with Prima is possible. The following is based on the Tk + MCE::Hobo demonstration (2nd example in the post). I tested Prima + MCE on Linux using CentOS 7.x and Windows with Strawberry Perl 5.22.x.

    use strict; use warnings; use MCE::Hobo; use MCE::Shared; use Prima qw( Application Buttons Label ); my $que = MCE::Shared->queue(); my $msg = MCE::Shared->scalar("Start"); my $hobo = MCE::Hobo->create("bg_task"); my $wm = Prima::MainWindow->new( size => [ 250, 200 ], text => 'Hello world!', onDestroy => \&quit ); my $lbl1 = Prima::Label->create( owner => $wm, size => [ 220, 50 ], text => 'Prima + MCE Demo', alignment => ta::Center, valignment => ta::Middle, pack => {} ); my $btn1 = Prima::Button->new( owner => $wm, size => [ 120, 50 ], text => $msg->get, onClick => \&fun, pack => {} ); my $btn2 = Prima::Button->new( owner => $wm, size => [ 120, 50 ], text => 'Quit', onClick => sub { $::application->close }, pack => {} ); my $timer = Prima::Timer->create( timeout => 100, onTick => sub { my $new_text = $msg->get; if ($new_text ne $btn1->text) { $btn1->set( text => $msg->get ); } } ); $timer->start; run Prima; sub fun { $que->enqueue("some event"); return; } sub quit { $timer->stop; $hobo->exit->join; $::application->close; } sub bg_task { while ( my $event = $que->dequeue ) { $msg->set("Step One"); sleep 1; $msg->set("Step Two"); sleep 1; $msg->set("Step Three"); } }

    So that the quit function isn't called twice, I'm only calling $::application->close inside the Quit handler. That closes the window which then triggers the MainWindow's onDestroy handler.

    Regards, Mario

    Update: Updated the timer handler. Thanks zentara.

New Monk Discussion
The Cookies account
3 direct replies — Read more / Contribute
by Lady_Aleena
on Apr 26, 2017 at 04:47

    A little over four years ago, I created the Cookies account for fun. I was known for my chatterbox antics with cookies; so on April Fools 2013, I decided to have some fun. Two years ago I went in for surgery, which is scary. I was thinking something could happen, and Cookies would be left without someone to maintain the account.

    Some users still play with the buttons from time to time. I would not want the account to die just because I did. So, if anything happened to me, would there be someone who would be willing to take over this very silly account?

    P.S. I am always willing to add more flavors and options to the account. Just let me know.

    P.P.S. This thread can be for anything related to the Cookies account that might merit general discussion, too. 8)

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena, the Cookie Lady
Log In?

What's my password?
Create A New User
[james28909]: well i have officially wore my brains out on hash refs and array refs and hash of arrays
[james28909]: push @{$hash{$ref}}, $this, $that, $the_other;
[james28909]: for 0 .. 3 {print $hash{$ref}}$_;
[james28909]: or i guess that is a hash ref
[james28909]: hash of array ref <.<
[james28909]: im also about to embark on porting the discord api to perl, without having to have 400 dependencies...
[james28909]: would be nice to link doscord to irc and other services

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2017-05-01 03:36 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (544 votes). Check out past polls.