Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine


( #480=superdoc: print w/ replies, xml ) Need Help??

If you've discovered something amazing about Perl that you just need to share with everyone, this is the right place.

This section is also used for non-question discussions about Perl, and for any discussions that are not specifically programming related. For example, if you want to share or discuss opinions on hacker culture, the job market, or Perl 6 development, this is the place. (Note, however, that discussions about the PerlMonks web site belong in PerlMonks Discussion.)

Meditations is sometimes used as a sounding-board — a place to post initial drafts of perl tutorials, code modules, book reviews, articles, quizzes, etc. — so that the author can benefit from the collective insight of the monks before publishing the finished item to its proper place (be it Tutorials, Cool Uses for Perl, Reviews, or whatever). If you do this, it is generally considered appropriate to prefix your node title with "RFC:" (for "request for comments").

User Meditations
-Ofun times
4 direct replies — Read more / Contribute
by raiph
on Apr 12, 2014 at 00:35
    This post is about the immature Perl 6, not the rock solid Perl 5

    In the last few months jnthn has added optimizing stages to the Rakudo/NQP/backends compiler stack. In his latest blog post he outlines these stages and notes some early results from a few things he and timotimo have already done ("Array and hash access is more than 3 times faster, most multi-dispatches are now enormously cheaper").

    There's other news too, so even if you're not ready for -Ofun the linked blog post is still worth a read if you are interested in P6.

RFC: API for declarative parameterized web queries
3 direct replies — Read more / Contribute
by smls
on Apr 10, 2014 at 17:17

    Hello all!

    Since I'm doing web querying/scraping of tabular data in several of my scripts, I want to refactor this functionality into a convenient module, and I would appreciate some input/criticism/wisdom from the other resident monks on that topic... :)

    By "query", I mean a complete recipe for downloading a document from the web and extracting relevant pieces from it using XPath expressions and/or regexes.
    By "tabular data", I mean that when a query is executed, it returns a list of items where each item has the same set of pre-defined "fields".

    The module's API should allow query definitions to be:

    • encapsulated - Everything that defines a particular query, should appear together as one self-contained unit in the user's source code.
    • declarative - Don't make the user write unnecessary boilerplate code or worry about implementation details.
    • reusable - Once a query is defined, it should be very easy for the user to execute it many times with different parameters during the program's execution.
Carrying (mini)CPAN
1 direct reply — Read more / Contribute
by fishy
on Apr 05, 2014 at 10:47
    Thanks to minicpan, I keep a local copy of the latest versions hosted on CPAN.
    Running minicpan weekly, I keep it up to date.
    My .minicpanrc file:
    local: /home/netbook/minicpan/miniCPAN_20140405/ remote: http://your.favorite.cpan.mirror/ also_mirror: indices/ls-lR.gz
    Now, I want to carry my local minicpan keeping it on a memory stick.
    Changing .minicpanrc to:
    local: /media/USB16GB/miniCPAN_20140405/ remote: file://home/netbook/minicpan/miniCPAN_20140405/ also_mirror: indices/ls-lR.gz
    and running minicpan again, sweeps my minicpan onto my stick.
    Now, I can install any module offline (as long as specific version dependencies are satisfied).
    Just mount my stick and either, first time running cpan:
    ... Would you like to configure as much as possible automatically? [yes] ... sites for you? (This means connecting to the Internet) [yes] no ... Would you like to pick from the CPAN mirror list? [yes] no ... Please enter your CPAN site: [] file:///mnt/minicpan Enter another URL or ENTER to quit: [] New urllist file:///mnt/minicpan/ Autoconfiguration complete. commit: wrote '/home/userOne/.cpan/CPAN/' ...
    or by modifying manually ~/.cpan/CPAN/
    ... 'urllist' => [q[file:///mnt/minicpan]], ...
    So, it's easy installing modules on offline systems or installing apps on user (e.g. /home/user) Perls.

    Have fun!

    UPDATE: After discovering how to comment, my .minicpanrc looks like:
    ## web ---> local disk (computer A) #local: /home/netbook/minicpan/miniCPAN_20140414/ #remote: http://your.favorite.cpan.mirror/ #also_mirror: indices/ls-lR.gz ## local disk (computer A) ---> USB local: /media/USB16GB/miniCPAN_20140414/ remote: file://home/netbook/minicpan/miniCPAN_20140414/ also_mirror: indices/ls-lR.gz ## USB ---> local disk (computer B) #local: /home/dan/miniCPAN/miniCPAN_20140414/ #remote: file://media/usb/miniCPAN_20140414/ #also_mirror: indices/ls-lR.gz
Wrong + Right = Even Worse
8 direct replies — Read more / Contribute
by choroba
on Apr 03, 2014 at 09:39
    In a legacy project at work, we have lots of scripts that should in fact be modules. But they declare no package, use the .pl extension and call each other via require. Originally, the full paths were used in require, which constituted one of the obstacles to run the project locally. I replaced all the occurrences of
    require '/path/to/some/';


    use lib '/path/to/some'; require '';

    and I was able to run some of the scripts locally (I had to add some paths to @INC).

    After several days, we noticed some of the scripts failed. I inspected the code and discovered that there was one newer OO module that was written "correctly": it lived in a .pm file and declared a package. It used lib and only required the script names.

    Combining "right" and "wrong" led to "even worse": The OO module required several .pl files. All the subroutines they declared were therefore created in the namespace of the module. Later, when a calling script required the same .pl file, it already existed in %INC, so it was not read again. No import was called anywhere, so the subroutines did not appear in the main:: package.

    Here are sample files so you can try it yourself:

    package module; use warnings; use strict; require ''; subroutine(); warn 'module INC: ', $INC{''}; __PACKAGE__

    #!/usr/bin/perl use warnings; use strict; warn "Loading 1"; sub subroutine { my $file = (caller)[1]; $file =~ s=.*/==; warn 'subroutine defined in ', $file; } subroutine(); 1;

    #!/usr/bin/perl use warnings; use strict; use FindBin; use lib $FindBin::Bin; require ''; use module; warn 'script INC ', $INC{''}; subroutine();


    The Conclusion

    We now have 2 options:

    1. Revert to the original full-path style require with no possibility to run the project locally.
    2. Refactor everything to proper modules. 100,000+ lines.


    I just had an idea: there is a third option. In the OO module, store %INC at the beginning, do all you need, then set %INC back to what it was.

    my %_INC = %INC; # ... %INC = %_INC;
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Presenting for your enjoyment: Acme::Thoroughly::Modern::Perl
3 direct replies — Read more / Contribute
by boftx
on Mar 31, 2014 at 23:33

    Its mission: To boldly go where no Perl has gone before!

    Okay, I really wanted a Monty Python reference but I can't come up with a good one right now. :(

    Anyway, coming to a CPAN near you on or about April 1, I give you, Acme::Thoroughly::Modern::Perl!

    package Acme::Thoroughly::Modern::Perl; use strict; use warnings; our $VERSION = 'v0.4.1'; my @now = localtime(); my $yr = $now[5] - 100; # This actually calculates what might be the current minimum version # for years >= 2010. my $mver = ( ( $yr - 10 ) * 2 ) + 10; # just in case there is a boundary case, wrap the test in a do/while # and step it up as needed. my $req_str; do { $mver += 2; # skip over devel releases my $verstr = sprintf( "%0.3f", 5 + ( $mver * .001 ) ); $req_str = "require $verstr"; } while ( eval "$req_str" ); # we need to warn and exit, and NOT die, if we want to more closely em +ulate # what is actually printed for a real failue. we exit with 255 because # that is what perl does. (but override in a test environment since it + would # really suck to have 100% failures on the test matrix!) unless ( $ENV{ATMP_TEST} ) { warn "$@\n"; exit 255; } 1; __END__ =pod =head1 NAME Acme::Thoroughly::Modern::Perl - Go where no Perl has gone before! =head1 SYNOPSIS use Acme::Thoroughly::Modern::Perl; =head1 DESCRIPTION This module allows one to not only be on the bleeding edge of Perl, bu +t to go beyond! Unlike other modules that attempt to include advanced features, there +is no need to specify a given version or release year. Acme is committed +to making the user experience as simple and error-free as possible and automatically does all of this for you! =head1 BUGS ACME is perfection! (Time machine not included.) =head1 AUTHOR Jim Bacon, E<lt>jim@nortx.comE<gt> =head1 COPYRIGHT AND LICENSE Copyright (C) 2014 by Jim Bacon This library is free software; you can redistribute it and/or modify i +t under the same terms as Perl itself, either Perl version 5.010001 or, at your option, any later version of Perl 5 you may have available. =head1 DISCLAIMER Finding a way to use this module, and the consequences of doing so, is + the sole responsibility of the user! =head1 NOTE Acme employs the finest technology available to ensure the quality of +its products. There are no user-servicable parts inside. For your own safe +ty, DO NOT EXAMINE THE CONTENTS OF THIS PACKAGE! =cut
    It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.
too much free time
3 direct replies — Read more / Contribute
by Anonymous Monk
on Mar 30, 2014 at 15:51
    #!/usr/bin/perl -w use strict; use Email::Send; use Email::Send::Gmail; use Email::Simple::Creator; my $to = $ARGV[0]; my $from = $ARGV[1]; my $pass = $ARGV[2]; my $prog = (split /\//, $0)[-1]; die "\n\tusage: $prog to from pass\n" if(!$to || !$from || !$pass); for(my $i=99; $i>0; $i--){ my $y = $i - 1; my $bottles = 'bottle'; $bottles .= 's' if(!($i == 1)); my $line = "$i $bottles of beer on the wall, " . "$i $bottles of beer, take one down " . "pass it around, $y bottles of beer " . " on the wall.\n"; my $email = Email::Simple->create( header => [ From => $from, To => $to, Subject => '', ], body => $line, ); my $sender = Email::Send->new( { mailer => 'Gmail', mailer_args => [ username => $from, password => $pass, ] } ); print $line, "\n"; eval { $sender->send($email) }; die "Error sending email: $@" if $@; }
"warn" is your best friend
4 direct replies — Read more / Contribute
by snax
on Mar 23, 2014 at 00:14
    It's been nearly ten years since I've said anything here. Somehow, this seems appropriate. I, as many perl hackers have, tend default to quick "print" statements for debugging, only to be shot down when throwing my code at, say, multiple input files at once, for example. No longer. Sure, your code works for *most* of the files, but something is twitchy somewhere. Unicode when you expected ASCII. A mix of LF/CRLF line endings. CR line endings (horrors!) even :) But: if you print where you think things are going wrong, that output goes in the STDOUT queue. The errors that pop when things go wrong happen in the STDERR queue. Hence, "warn" is your bestest friend evars! Trust me on this. You'll get all sorts of win using "warn" context points when you want to debug via print-ing.
Unexpected Python News
8 direct replies — Read more / Contribute
by McA
on Mar 18, 2014 at 04:11

    Hi all,

    just read Garbor's article at yesterday. Plus all the comments to that topic. Nothing really new.

    But today I opened my mailfolder finding the XING newsletter (something like LinkedIn for those who don't know) with the following head line: "Etliche Neuerungen in Python 3.4" (more or less: Several new features in python 3.4).

    The fact that this is actually the subject of the newsletter is really interesting. Besides the fact whether it is important or not to have focus on Perl I'm pretty sure they don't talk about perl when a new Perl release gets out.

    Best regards

    P.S.: It would be interesting to know if Python is a building block at XING.

local::lib - installed by default
3 direct replies — Read more / Contribute
by wmehl
on Mar 11, 2014 at 11:52


    I have a humble request - that the mod local::lib be installed by default at part of CPAN, and not as a separate install. FTP and HTTP are supported "out of the box", we are asking the same for local file. This would allow a local repo of CPAN to be used out of the box via filesystem. This may mean that local::lib no longer exists, it is rolled into the base CPAN code.

    It is a chicken/egg scenario, in order to install from fileshare, you have to have local::lib installed. This requires going to the net for CPAN install, which in our case is not allowed.

    There are work arounds (boot strap, rpm's, etc) but it would be nice to use a local repo native to CPAN out of the box.

    The use case, many servers (1000) in a commercial environment. We have no direct access to the internet, and we have to use a vetted source for CPAN on a local fileshare, not public repos via FTP or HTTP. We could bring up a local HTTP repo, but would prefer to use fileshare

    Thanks for your time an consideration.

Something to meditate on -- the need for a trendy perl?
10 direct replies — Read more / Contribute
by perl-diddler
on Mar 11, 2014 at 11:19
    New version of vim came out for windows... had x86 support -- went to look -- had support for running scripts in Lua, Ruby, Python 2 and Python 3 and no perl.

    I asked if it was an error, and 1 version of perl might not be needed vs. 2 for python.

    The reply I got:

    Dear Linda, It feels like Perl is not very trendy these days. Support for that man +y languages was added because certain popular plugins are written par +tly (or fully) in these languages rather than Vim Script. Python is p +robably the most popular language for extending Vim right now, perhap +s after Vim Script. Ruby goes next, then Lua. But I've never came acr +oss a single plugin which would rely on Perl to be honest. May I ask +why you think that Perl is so important for that Vim distribution? Regards, Alexander
    I doubt benchmarks on multiple thread execution would be considered trendy. Ideas? Thoughts? Examples or counterpoints?
Job With Fun meditation
2 direct replies — Read more / Contribute
by project129
on Mar 09, 2014 at 13:34

    Hello dear monks!

    to be clean in my speech: I just looking for my next telecommute contract with mojolicious and modern (sure depends on what you think modern perl are :)) perl.

    And can not find anything real during last 3 months...

    I am not too greedy (really my hourly rate are not huge),

    I am not (suppose) too lazy or (really suppose :) ) too stupid ... but all proposed projects was related to old cgi style or (not interested) catalist framework :(

    I just wanna my next project to be interesting and use tools that really interesting for me :( Am i dream too much? My wishes (work with fun) not real?

    Please share you experience:
    - are things are going really bad (for my expectations) in perl market? (support old/poor coded apps dominate)
    - any success story?
    - any mojo fans here? :)

    sorry for disturbing you
    with best regards
Announcing Data::DynamicValidator
1 direct reply — Read more / Contribute
by basiliscos
on Feb 20, 2014 at 14:50

    Hello dear monks!

    I regularly met the problem of arbitrary data structures validation, which comes in form either hierarchical config or JSON data. The substantial idea, I got from one of Perl books (I think, this is Hight Order Perl) is the following: the programming languages have tendency to be declarative (i.e. declaring/describing the result, but not the way, how to archive it) but they'll never completely be so, because it seems to be possible only in some local areas.

    When such a local area is been invented, then an extremely useful micro-language will appear. For example, well known regular expressions for the area of arbitrary text data matching/extraction. Another successful example I know is the XPath (or XPointer?) technology for nodes matching in XML documents.

    The last one seems to be very successful in addressing data nodes, that a lot modules appeared, that try to mimic XPath behaviour: Data::DPath, Data::SPath, Data::PathSimple, Class::XPath.

    Well, XML seems to be not too modern, too heavyweight, too enterprisish. So, the minor brother, not overcumbered with namespaces and processing instructions, appeared. It is JSON. The related data extractions/matching technology appeared a bit later; this is JSON pointer: JSON::Pointer, Mojo::JSON::Pointer.

    So, my intention was to develop module, which takes the best from the two worlds: declarative data path selection (a-la JSON Pointer and XPath, but not as simple as the first, and (yet) not as complex and feature-rich as the second), and from the perl (closures, flexibility, application agnosticism, DWIM and DRY principles).

    Here come a few snipplets, from which you can judge about the module

    use Data::DynamicValidator qw/validator/; my $data = { ports => [2222] }; my $errors = validator($data)->( on => '/ports/*', should => sub { @_ > 0 }, because => 'At least one port should be defined at "ports" section', )->errors; if(!@$errors){ say "all ok"; } else { say $_->reason for(@$errors); }

    So, it generally, it uses triplets: on (specifies data path), should (specifies testing perl closure for the results of data path selection), and because (defines human-readable string for administrator to say/describe him the errors in a config, or for HTTP client developer, that something is missing in JSON input data).

    A bit more complex example. Say, you want to check that all declared ports should be available for the application at startup. So, you should do the following:

    use Net::EmptyPort qw(check_port); my $errors = validator($data)->( on => '/ports/*', should => sub { @_ > 0 }, because => 'At least one port should be defined at "ports" section', each => sub { my $port = $_->value; shift->report_error("The port $port is not available for usage") if(!check_port($port)); } )->errors;

    The more complex examples are available in metacpan.

    Constructive critique and suggestions are more then welcome!

in praise of poor old Tk
4 direct replies — Read more / Contribute
by zentara
on Feb 18, 2014 at 06:05
    You know, when I first started programming, about 20 years ago, I thought Perl/Tk was the ticket. Finally something which allowed you to make your own GUI's without having to resort to buying Microsoft software. It worked great, and still works great.

    In the meantime, other GUI toolkits, such as the short-lived Gtk, Gtk2, and currently Gtk3, and others such as Wx and KDE have come along. But they are always changing so fast, to incorporate such great new features as semi-transparencies, gradients, and whatever new themeing engines they might want compatibility with.

    So, I look back at Tk, knowing that for the most part, all my scripts still run pretty much as I wrote them way back when. It is simple, and stable. My newer Gtk2 scripts, may not convert without some work, to Gtk3. Additionally, the docs for Gtk3, Wx and ( KDE ) Qt GUI's are hard to come by.

    But just look at the Tk code base. It needs no pre-requisite libs to be installed, and is a very small module compared to the GUI potential, which it contains. In days of heightened security over code safety, Tk is an easy to module to deal with. Additionally, if you do need transparency and all the matrix operations like rotations, the Tk::Zinc module works great. It is now somewhat abandoned code, but the module still works, and it used to be used as the air-traffic display driver for some French airports. So you know it isn't junk software. It comes with a nice pdf manual, documenting all it's features.

    It is kind of funny to me, that the entire drive to make more advanced toolkits, was so that the themeing engine of the host computer would decide how the window app would look. Many like the simplicity of Tk's ability to individually set each widget's colors and fonts with a few simple lines, like -bg=>'#112233', instead of needing a special style section to overide the system's style settings.

    Anyways, I still reach for Tk whenever I need a GUI app. It is suitable for almost all small custom tasks. I would even trust it for digital guages and controls.

    ... and it's way easier to write code for, than any other toolkit out there

    I'll bet Perl/Tk will still be around after Gtk5 and Wx99 are come and gone. :-)

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Levels of strictness and compatibility
2 direct replies — Read more / Contribute
by Anonymous Monk
on Feb 16, 2014 at 18:05
Buying a round for your friends
3 direct replies — Read more / Contribute
by ribasushi
on Feb 11, 2014 at 05:57
    Since I want my braindump from an hour ago to reach as far within the community as possible, I figured I will repost it here as well (given the core crowd of perlmonks does not really read such things). Note - *THIS IS NOT A PERSONAL FUNDING-DRIVE*. This is about figuring out how hopelessly stuck-up as humans we are collectively, in our corner of the proramming universe.

    Original text taken from here

    Given our community is a little... let's say cautious I feel the need to open with a disclaimer. I am in no way affiliated with Gittip, in the past, present and the foreseeable future. In fact I looked at their bugtracker for the first time this morning and am appalled that a site in production for 2 years can have so many outstanding basic conceptual issues.

    In any case this entry is about the underlying idea, so if you can manage to not get distracted by a shoddy implementation - read on (NSFW language as always :)

    It started yesterday when I looked here and asked Y U NO WANT BEER?!. While twitter did not manage to spark a conversation, IRC did (and boy, was that some conversation :) The chatter quickly evolved, climaxed and (painfully predictably) broke away for good. And also predictably it boiled down to a split into several distinct camps

    • Some genuinely believe it is not worth bothering with chump change, since "we lack the hipsters in our community" and without them any kind of funding drive will not have an impact
    • Some feel uncomfortable seeing their avatar among the current highest donors/receivers (after you look at the current top receivers you either instantly understand what the problem is, or you don't - there is no easy way to explain it)
    • Some genuinely believe they rather get patches as opposed to chump change

    I say FUCK THAT. And instead of explaining how and why you should do something you are not currently doing, I will instead explain why I am currently pledging $50 (possibly more in the future) per week, and distribute them among folks of my choosing.

    First of all: it is easy for me to do so (and yes, this part is important). Connect my twitter / github / bitbucket / whathaveyou account, connect a credit card: done.

    With that out of the way - let's take a simple example - Pumpkin Perl and the current Pumpkin (or Pumpking depends on what you like). At the time of writing Perl is #3 on the metacpan leaderboard, with 168 "backers". If these 168 decide to give our pumpkin $5/week each - that's roughly $3500 per month for him right there.

    THIS JUST IN, BREAKING NEWS: chump-change adds up.

    Now, am I confident he will use the cash to further my interests (that is keep Pumpkin Perl sane) in the foreseeable future? Yes, I am pretty confident, given track record and all that. But the more important question is - does it matter if he actually does? Not in the slightest. I am not sharing some chump-change with expectations of extra commitments and future results.

    I am virtually buying my fellow colleagues a beer for EXCELLENT OUTSTANDING WORK *ALREADY COMPLETED*

    What I particularly like about Gittip is that it does not require any extra effort to keep doing what I decided to do. Yes, I could go broke by oversharing my extensive wealth, but so could anyone with a non-dumb phone and an appetite for extra game content. At least I'd know there is an actual person (that I might even like) on the other end ;)

    Will I feel cheated and sad if none of this goes anywhere? If the virtual beers do not motivate anyone, and if the Perl-portion of the Gittip community remains unseen and insignificant? Not really. $50 is the cost of a decent-but-not-spectacular dinner for two where I live. If this is cash that ended up being thrown away - shrug, it could have been a shitty dinner anyhow. And if I *do* feel bad about it - this means I am a petty shithead and I deserve to feel like that anyway :)

    So to recap:

    • It is easy
    • It doesn't cost me much of anything
    • It can make a real tangible difference on the other end
    • It sends a clear continuous "Thank you!" message
    • Makes Perl as a whole look good, without compromise of my values
    • No hipsters required (though of course welcome)

    What's not to like?


Add your Meditation
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • 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 studying the Monastery: (12)
    As of 2014-07-22 08:10 GMT
    Find Nodes?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:

      Results (106 votes), past polls