Bleg: Why the alternating result?

I know I made a mistake by doing a double glob, but why this pattern of output? Note, there is only one file matching /etc/magic.* and two files matching /etc/magic*, and none matching /etc/magic.dragon*

% perl -E'say (glob </etc/magic.*>) for 1..10'
/etc/magic.mime
2
/etc/magic.mime
4
/etc/magic.mime
6
/etc/magic.mime
8
/etc/magic.mime
10

% perl -E'say (glob </etc/magic*>) for 1..10'
/etc/magic
/etc/magic.mime
3
/etc/magic
/etc/magic.mime
6
/etc/magic
/etc/magic.mime
9
/etc/magic

% perl -E'say (glob </etc/magic.dragon*>) for 1..10'

I'm really hating Perl's context today.

Dan Meyer on math, Alan Kay on physics, and the Pharo tutorial

Dan Meyer has a nice TED talk about math pedagogy:

I find it very similar to Alan Kay's TED talk where he shows off various Smalltalk things to illustrate physics concepts:

The best introductory programming book I have ever seen (and I've seen a lot in many languages) is Squeak: Learn Programming with Robots, which many people might recognize as a very LOGO like introduction.

Along with that, I was quite intrigued with Pharo's introduction to Smalltalk. This world has a tutorial class. When you first open the world (which is just double-clicking the icon of the single file you downloaded), the big window tells you exactly what to do first then leads you through a 24 step tutorial of the entire language and some of the tools:

If you haven't run into Smalltalk before, its world is what many other languages strive to be but ignore. Smalltalk is where the idea of a refactoring browser started, and what a lot of people want for Perl. I think a lot of the work going into Padre is really an attempt to force a Smalltalk-like world on Perl. I even tried to make my own Perl system browser, which I've now put it on Github although I don't use it anymore.

Introduction and API spec

Hello, good evening and welcome.

For the next few months I will be using this blog to help document and publicise my "Ctypes for Perl" project. The project is being carried out for TPF under the auspices of the Google Summer of Code programme, and mentored by Reini Urban.

What's a ctypes?

'ctypes' is the Foreign Function Interface (FFI) library distributed with the Python core. It basically allows native C libraries to be called easily from Python; for module authors, it allows the wrapping of C libraries in pure Python.

This is obviously a powerful concept. Imagine a world where Perl module authors didn't need to use XS, and module consumers don't need to have a correctly configured compiler set up on their system. This is the purpose of the project: to create an easy, cross-platform, pure-Perl interface to native C libraries.

Implementations

2010 Perl Survey

Yeah, you've probably already seen this, but in case you haven't, read the Perl survey announcement and take the survey!

Perl::Critic --praise

Wouldn't it be cool if Perl::Critic had a --praise option?

It would tell programmers they have done something worth mentioning and throw in some inspirational kudos and uplifting recognition:

$ perlcritic --praise script.pl
Good! Filehandle is not a Bareword at line 4, column 1.  See page 202,204 of PBP.  (Cleverness: 1)
Nice use of comments in a regex. Maintainers will be happy at line 9, column 1.  See page 289 of PBP.  (Cleverness: 3)
Outstanding use of Moose roles at line 11, column 1.  (Cleverness: 2)
Named parameters are definitely easier to read at line 42, column 1 (Cleverness: 1)
Quite sure this 1 line of Perl translates to at least 12 in Java at line 58, column 1 
Oh yeah! You rock! at line 74, column 1.  (Cleverness: 4)
This package may be useful to the community. Make sure you upload it to the CPAN at line 74, column 1.  (Cleverness: 5)

I think psychologists call it positive reinforcement. :)

Extracting and accessing the release history in perlhist

I needed to make some charts showing the sequence of perl's releases, so I wrote some code to extract all that from perlhist. I thought I might turn it into a module or add it to Module::CoreList, but I have a lot of other things I need to do. If someone else wants to do that, however, here's my script:

The Perl Survey 2010 is ready for you to complete!

Finally after many delays, the Perl Survey 2010 is ready for participants to complete. It should take you about 10 to 15 minutes. The purpose of this survey is to find out information about programmers who use Perl, the tools that they use, and their opinions about Perl. The survey is funded by The Perl Foundation, with hosting support from Strategic Data and Shadowcat Systems. We plan to re-run the survey every two to three years to see how the community changes over time.

So please fill in a questionnaire yourself by visiting the Perl Survey website. Once you've done that, please tell your friends, tell your friends friends, and your friends friends friends. We don't just want heavily involved members of the Perl community to complete the survey but more casual Perl programmers as well. The 2007 survey managed about 4,000 responses, but I'd be happy with around the 1,000 mark.

I'll be presenting the initial cut of the data analysis in three weeks time (Week beginning June the 5th) at the German Perl Workshop.

No semicolon after return values

Perl lets you omit semicolons at the end of a block. That is, you can treat ; as a statement separator, not a terminator, as in Pascal.

OK, but why would you want to do that? The advantage of terminating each statement is that you don't need to do anything special for the first and last lines: You can insert or remove lines at any point without worrying about the rest of the code. Why throw that away?

Because sometimes it doesn't make sense to add code at the end. Consider this code:

sub foo {
  my ($s) = @_;
  $s =~ s/%/%%/g;
  $s
}

Programmers need a muse

The Muses in Greek mythology are the goddesses or spirits who inspire the creation of arts; they were considered the source of the knowledge. And I believe as a programmer you need your muse.

Most of the time whenever I talk with people about what I do, they automatically start picturing me as some kind of a robot which rambles on for hours in a language they don't understand, but computers do.

I don't blame them, it's hard to put "computer" and "free-will" in the same sentence, because computers are nothing but machines that follow orders, no matter how complex these might be; and in that mindset, they don't put "creativity" near "computer".

But programmers are not machines, we are the ones that tell them what to do, and in that, there is an amazing amount of creativity: as we have the power to create.

Just want to know WNOHANG...

package MyApp;
# I just want to know WNOHANG from sys_wait_h ... [-;

our $WNOHANG_VALUE ||= `$^X -MPOSIX=:sys_wait_h -e "print WNOHANG;"`;
sub WNOHANG () { $WNOHANG_VALUE }

!!'^^';

sigh maybe useful for a long-time running program if you are sensitive to memory usage..

So mst lost iron man

It was fortuitous that I joined Iron Man at this late stage as now I get to vote for mst's forfeit!

Test-driving MongoDB on a Moose

I spent a few hours this last weekend trying out MongoDB, and its Perl driver.

I was curious to see how I could put NoSQL databases to good programming use. MongoDB stroke me as a good contender for some experiments: it's easy to install, well documented and has an intuitive query language that reminds me of SQL::Abstract syntax. Besides, MongoDB allegedly is very fast and scalable, which left me wondering how my configuration management apps could benefit from a backend switch from relational to a non-ACID document based DB like MongoDB, just like these people did for their server monitoring software.

Threaded Forum SQL

I previously wrote about threaded forums and threatened to share some code with you. Basically, I want to get this in a single SQL call:

Threaded Forum

SproutCore and Tatsumaki

I added a Perl backend version of the SproutCore tutorial to the wiki. It was useful to see how Tatsumaki (the new framework by Tatsushiko Miyagawa) worked, and also because PSGI is quite fun to use!

version.pm: just say no

Thanks to the CPAN testers, I have found out that there is an exciting bug in version.pm. Somewhere in between versions 0.74 and 0.82, qv()'s behaviour changed, and so my CPAN::ParseDistribution started failing two of its tests.

There's no reason to ever use version.pm, which only exists to support the absurd practice of using things other than number as version numbers. Use of version.pm makes tools for dealing with the CPAN an order of magnitude more complex.

USE OF version.pm IS A BUG. STOPPIT!

Depth-first nodetree

Ovid posted an interesting question about how to sort threads in a forum so you'll get the posts that belong to each thread before the next thread starts. Perl part here.

The question is,

Can I do that in straight SQL (this is PostgreSQL 8.4) or should additional information be added to this table?
As a matter of fact, in PostgreSQL 8.4 you can do it in straight SQL with no further information necessary. I will show how.

To set up the example we'll need a table:

CREATE TABLE nodes (
	id int PRIMARY KEY,
	parent int REFERENCES nodes(id)
);

and some data:

BioPerl has migrated to GitHub!

For the full details, see here!.

(and yes, I'm too lazy and tired to type that again...)

On RJBS's automatic version numbering scheme

Everytime I browse through CPAN recent uploads, and see versions of modules with RJBS's automatic numbering scheme, like 2.100920 or 1.091200 I tend to read it as 2.(noise) and 1.(more noise).

The problem is that it doesn't look like a date at all (is there any country or region using day of year in their date??). I've never been bothered enough with this though, as I don't use this scheme myself, but have always had a suspicion that this obfuscation is deliberate for some deep reason.

Turns out that it's just a matter of space saving and floating point issue. I'm not convinced though, is x.100513n (YYMMDD, 6 digits + 1 digit serial = 7 digits) really that much longer than x.10133n (YYDDD, 5 digits + 1 digit serial = 6 digits)? Is there a modern platform where Perl's numbers are represented with 32-bit single precision floating point (only 7 decimal digit precision) where it will present a problem when n becomes 2 digit using YYMMDD scheme?

Microsoft Attack CPAN Testers (Again)

Back In January, I reported how Microsoft had launched what amounted to a denial of service attack on the CPAN Testers server. It seems that 4 months later, we have yet again been targeted for attack from Microsoft. After the last attack, any IP address matching '65.55.*.*', hitting the main CPAN Testers website, was blocked (returning a 403 code). Every few weeks I check to see whether Microsoft have actually learnt and calmed down their attack on the server. So far, disappointingly, despite an alleged Microsoft developer saying they would look into it, the attack on the server has continue with little alteration to their frequency and numbers. Had they changed and been considerably less aggressive I would have lifted the ban.

Measuring Rakudo performance

You can now create "statistics" about Rakudo performance (perhaps to augment your "lies" and "damn lies" ;-) using new funtionality added to the 'tools/test_summary.pl' script. It's under the title "Simple Relative Benchmarking", and needs at least two runs to give usable data. Please try it, and compare findings in #perl6.

With up to about 2% additional run time, test_summary gets Rakudo's Test.pm to emit per-test timestamps to microsecond resolution. Then test_summary calculates the (real) execution time of each of the more than 30000 spectests and inserts the results into 'docs/test_summary.times' in JSON format. That accumulates the results of the five most recent complete runs in FIFO fashion, occupying about 2.5 MB.

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.