One-liner to count the number of lines in a file

There is a cute Perl one-liner to count the number of lines in a file:

perl -nE'}{say$.' foo.txt

Let's see how perl parses this one-liner:

mention of Perl in a fun story

Especially I like last line. Wikileaks To Leak 5000 Open Source Java Projects With All That Private/Final Bullshit Removed.

P.S. Stevey's Tech News, Issue #1 is also fun.

Morpheus - ultimate configuration engine

As I promised, here are the slides from my talk this morning at Saint Perl-2 in Saint-Petersburg, Russia.

I believe Morpheus can be very useful for the community and hope that it'll become widely adopted.
There are still a lot of things which can be added, but conceptually we are on the right track.

These slides probably suck (I wrote them in the last moment and didn't put enough details in some places), but putting code out in the wild and getting feedback is more important by now.

One more thing, if you're going to check out PODs in next few days, see them on github instead of CPAN. There are much more of them added in 0.36 release, which is not uploaded to CPAN yet.

UPD: Just found out that 0.36 release docs can be viewed here: http://search.cpan.org/~mmcleric/Morpheus-0.36/
Morpheus::Key, Morpheus::Bootstrap and Morpheus::Plugin::Content PODs are worth to be looking at, if you are interested in implementation detals.

Backlogging...

It has been quite a while since I last wrote. I think this is how 50% of blog entries around the world begin.

I've amassed a bit of a backlog over the last few weeks, and blogging was a part of it. This is the rest of the backlog.

Scalar context gotchas

On Twitter, Curtis Poe (@OvidPerl) posted some interesting and unintuitive Perl code; I've slightly reformatted it and changed some values for the sake of the following discussion.

use Data::Dumper;
sub boo { 4,5,6 }
my @x = ( boo() || 5,8,7);
print Dumper \@x;

What do you think this prints?

Let's look at some simpler examples of code:

$ perl -le'@x = (4,5,6,7,8); $y = @x; print $y'
5

An array like @x, in scalar context, evaluates to the number of elements in that array. In this case, @x contains five elements.

$ perl -le'$y = (4,5,6,7,8); print $y'
8

Any::URI::Escape percent encoding issues

In case you haven't seen it yet, Mark Stosberg posted an excellent analysis of percent encoding issues in several CPAN modules, including Any::URI::Escape, a module I whipped up one weekend - http://mark.stosberg.com/blog/2010/11/percent-encoding-uris-in-perl.html

Grantreport - Perl 6 Tablets - 5th week // Perl 5 Testing

By week i mean 7 days in which I touched the tablets.

Basically i just read the advent calendar and other sources and check if the tablets missing something. This way Appendix A has 25 entries more, much more revamped finding even keyword fossils of ancient Perl 6, not even known to moritz++, jnthn++ was helpful too. Also wrote the section about quoting and some minor parts of tablet 3.

Other than then I wrote last week an article for the next (10th) Perlzeitung about basics in Perl testung, because even beginners can't start too early with that. Since Perl's official Testing site lies pretty dormant I maybe take the brush to sweep there some things. but hej bigmouth I dont even got time follow properly p5doc and still in the starts for my thingy for the perl ecosystem group (still a seakrit). But my anger toward that subject rises. Any other volunteers for that out there?

The Definitive Guide to Catalyst book

Is the book worth buying?

Install dependencies of a Dist::Zilla-based distribution

For a distribution that is built using Dist::Zilla, it is very easy to install all the dependencies:

dzil listdeps | cpanm

dzil listdeps will almost build the distribution so it can determine the prerequisites and then list them each on one line. This list can be passed directly to cpanm.

Migrating 76 tables out of MS-SQL. Thanks DBIx::Class!

Just another day at the office moving databases into MySQL. 10 lines of DBIx::Class::Schema::Loader make_schema_at() and I'm done. :)

Usually.

Unfortunately today the table names "Order" and "Service-tier2" blow up:

Bad table or view 'Order', ignoring: DBIx::Class::Schema::Loader::make_schema_at(): DBI Exception: DBD::mysql::st execute failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Order WHERE ( 1 = 0 )' at line 1 [for Statement "SELECT * FROM Order WHERE ( 1 = 0 )"] at refresh_schema.pl line 9

Apparently "Order" is semi-reserved by MySQL, and dashes are trouble:

SELECT * FROM Order              # syntax error
SELECT * FROM `Order`            # works
SELECT * FROM Service-tier2      # syntax error
SELECT * FROM `Service-tier2`    # works

Another point for irc.perl.org #dbix-class, as ilmari pointed me to quote_char as the cure for what ailed me.

AnyEvent and Dancer: CondVars

In my last post, I explained how to get an AnyEvent->timer to work in a Dancer application.

There’s nothing wrong with timers, but if you are using AnyEvent, you usually have to deal with CondVars. There are two things you can do with a CondVar: Either you register a callback which will be called when the CondVar is triggered, or you call recv and it will block until the CondVar is triggered. In a route of your Dancer application, you probably want to block until you got all the data you want to display to your user.

Take the following (made-up) example which uses a CondVar:

SF.pm January 2011 - blekko: a web-scale search engine written in perl

Our 2011 January meeting will feature Greg Lindahl speaking about blekko. Location forthcoming.

blekko is a new Web-scale search engine, offering focused searching using "slashtags", which enable you to restrict search results to the specific sites of actual interest. We'll use some open-source slashtags as examples. The rest of the talk will focus our implementation of the search engine and the underlying NoSQL database using Perl+XS, Map/Reduce done better, tuning Linux for good performance, etc.

Greg Lindahl is CTO at blekko. He was previously a founder at PathScale, where he was the architect of the InfiniPath low-latency InfiniBand HCA, used to build tightly-coupled supercomputing clusters. Prior to PathScale's founding in 2001, Greg worked on commodity Linux clusters at HPTi, including the 1999 Forecast Systems Lab system, which was the first time a Linux cluster won a conventional supercomputing procurement. Greg first used Perl before the Camel Book was written. Perl: the swiss army chainsaw of programming languages!


http://blekko.com/

Announcement posted via App::PM::Announce

RSVP at Meetup - http://www.meetup.com/San-Francisco-Perl-Mongers/calendar/15745947/

Moving House 2010-12-17

Hi Folks
Yes, I'm moving house tomorrow, so if I don't respond to your emails, just hold you breath until normal transmission is resumed...

Using dzil to install with cpanm

If you are creating a distribution using Dist::Zilla, you can install it using "dzil install". However, that will use the standard CPAN shell.

To make this work with cpanm, use:

dzil install --install-command "cpanm ."

Now if only Dist::Zilla allowed aliases like git did... I'd like to have something like this in ~/.dzil/config.ini:

[alias]
    instm = install --install-command "cpanm ."

search.metacpan.org: Building a Sexier CPAN Search

As we began working on iCPAN, we became aware of how problematic it can be to figure just exactly what is in the CPAN. More importantly, we became aware of things we really wanted to do when interacting with CPAN. Last month, Dave Rolsky posted some comments on a next generation CPAN search . He has a fairly extensive list of things which a CPAN search could offer and I'm more than inclined to think that he's on the right track.

A CPAN search site should:
  • be available to the wider community to clone, fork, patch, pull etc
  • let you upvote/downvote modules
  • have tighter integration with reviews, dependency reports etc
  • allow for complex searches

There are really so many things it could be. The problem, as I see it, is that this is too big a job for just one person and that may be where projects have stalled in the past.

Killing Yacc: 1, 2 & 3

The Good, the Bad and The Ugly

Angeleyescleef.jpgThe recent discussions about yacc made me feel a bit like Lee Van Cleef in an old spaghetti Western. Cast alongside Clint Eastwood, Van Cleef watched with great concern as one attempt after another was made on Eastwood's life. Van Cleef didn't mind Eastwood getting killed -- he just wanted to be the one to do it.

As some of you will have recognized, I am talking about a very interesting discussion started by a paper by Might and Darais entitled "Yacc is Dead". I am finding it very much worth reading as an example of clear and precise mathematical writing. With respect to the parser itself, my opinion is that Russ Cox's extremely well-informed blog post, "Yacc is not Dead", is an accurate assessment.

Moving House 2010-12-17

Hi Folks
Yes, I'm moving house tomorrow, so if I don't respond to your emails, just hold you breath until normal transmission is resumed...

Using AnyEvent and Dancer

In our Hackerspace RaumZeitLabor in Mannheim, Germany, we have a "Network Power Manager 2000" which is a device that has 8 power sockets and is able to turn these sockets on/off when told so via network. We use it to save some power when nobody is at our space.

That sounds quite nice, but we had to reverse-engineer the protocol. Afterwards, we noticed that only one (!) connection to that device is possible. So our first approach of using a little script to communicate with it was not optimal: It had timing problems because the NPM2000 took a little bit longer to close the TCP connection.

Therefore, I decided to write a little webapp using the excellent Dancer framework which talks to the NPM2000 and provides a nice API to the user(s). It also should keep one TCP connection open all the time to save the overhead of creating a new connection and waiting for old connections to close properly on both sides.

A Desired SQL Affordance

When talking about an affordances, it turns out that there are different definitions, but I like to think of an affordance as "an element of design which suggests the correct course of action", which seems to be pretty much what Donald Norman meant when he adopted the term. It's an elegant concept which, if applied properly, makes it easy to do the right thing and harder to do the wrong thing. However, sometimes you want to do the wrong thing, so an affordance which makes this impossible isn't the most useful in my book. I just want doing the wrong thing to be jarring enough that it would give anyone pause.

And this brings me to the following issue I often see in SQL:

SELECT count(*) 
  FROM employee 
 WHERE salary < 20000;

The best widget set to create a GUI program in Perl

Suggestions are welcome in which widget toolkit is the easiest to learn and use to create a GUI program in Perl. Most people suggest using Java and Swing as the easiest and the most accomplished language and widget toolkit to use. Yes, I could use Java and Swing but I would prefer to use Perl.

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.