
Tuesday, 18 May 2010
Getting back at mst

Friday, 9 April 2010
one-liner tip: aliases
alias pe='perl -E'
alias ppe='perl -pE'
alias pne='perl -nE'
alias pipe='perl -i -pE'
alias pine='perl -i -nE'
that alone saves me a whole lot of typing over the week :)
> pe 'say q[hello, lazyness!]'
> hello, lazyness!
It's also pretty easy to remember, since you just type 'p' for 'perl', followed by the main flags your one-liner has. Oh, and of course you also can pre-load your favorite modules, doing things like:
alias pe='perl -MData::Dumper -lE'
That's it, hope you enjoy it :)
Monday, 18 January 2010
Better output testing HTML and other long strings
Maybe Test::LongString's most common function is contains_string(), which you may know as Test::WWW::Mechanize's $mech->content_contains() method. When it fails, the failing test output shows the original string and the text it was trying to find:
# searched: "foo bar"
# can't find: "baz"
Problem is, when the original string is too long, you get only the beginning of it. This happens a lot when you're trying to find content inside HTML, like:
# searched: "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Trans"...
# can't find: "some random content"
Such output is only barely useful, and I got fed up of having to edit a test file manually, add diag() calls to see the complete output, then ack for the wanted string to see what went wrong. So I made a small patch to Test::LongString, which Rafaël promptly accepted (yup, he rocks, but we all know that ;-).
Now, whenever such test fails, you'll get two extra lines:
# searched: "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Trans"...
# can't find: "some random content"
# LCSS: "ome random content"
# LCSS context: "d="content" class="foo">Some random content!</div>"
"LCSS" stands for Longest Common SubString, meaning you get whatever matched the most inside the original content (note that LCSS is not the same as LCS, or Longest Common Subsequence, which would go for a non-sequential match as seen in diff-like outputs). And, of course, "LCSS context" means the surroundings of the LCSS string just found.
Now, just by looking at our example, we know exactly why the test failed, and we are free to fix either the test suite or the application.
Know what's best? You get all that for free, no need to change a single line in your tests. Just update Test::LongString to 0.12 or later and enjoy! :-)
Monday, 4 January 2010
First CPAN upload of 2010
2009 came and went, so here's to an amazing 2010 for the Perl world, with even more than we already accomplished last year :-)
And look at that, it's only day 4 of 2010 and we already saw over 200 CPAN uploads. But don't look just yet! See if you can figure out what was the very first package upload to CPAN in 2010 (CPAN-time, of course). No clue? Couldn't care less? Well, call me curious, but I had to look ;-)
January 1st had several heavy competitors: PDL, Chart::Clicker, POE... even Plack was this close from being the one. But our "winner" is a rather young package by Marty O'Brien. I'm talking about Forks::Super, in it's 12th release.
Forks::Super provides new definitions for the Perl functions
fork, wait, and waitpid with richer functionality. The new features are designed to make it more convenient to spawn background processes and more convenient to manage them and to get the most out of your system's resources. Take good old fork(), for example. Without arguments, it behaves just like it used to, but now you can also do stuff like: my $pid = fork { cmd => [ qw(/bin/prog opt1 $opt2 opt3) ] };
or my $pid = fork { sub => \&subroutine, args => [ @args ] };
Your can even set timeouts on your forks, queue jobs and obtain filehandles. Pretty cool, huh?
I haven't actually used it, but Marty took his time with a very comprehensive Pod, and even some information for windows users. So, if you usually use fork in your programs, be sure to check it out.
Until next time!
Friday, 4 December 2009
A special Date, a special someone.
1000
Talk about serendipity, finding out about this 3 days before the actual date!
Taking her to dinner now ;-)
Thursday, 26 November 2009
Thanksgiving
I believe today is Thanksgiving Holiday in the US. We don't celebrate anything like it in Brazil - heck, if it weren't for television most people here wouldn't even know about it - but I thought this would be a good time to say "Thank You" to the Perl community and CPAN authors, for making this such a nice language to work with :-)
I pay my bills coding with Perl, loving every minute of it, and I'm sure it wouldn't be half as fun if it weren't for the nice people behind the communities and all the awesome modules I get to use and rely on. Sometimes - and I know I'm not the only one - I spend hours and hours just browsing through CPAN like a developer's Wikipedia. Peeking over at recently uploaded modules is aways fun too!
So, today I pay my respects to some (not all, as I'd be here all week, if not longer - and I need material for next year :-P) of the CPAN authors of modules I use(d) over the years, and thank them. I'll also rate their modules and send them a private email to show my appreciation, just in case they don't ever read this.
- Thank you Gisle Aas for URI, Digest::*, LWP and the whole libwww-perl family (we can actually see that the CPAN universe owes you a lot. We all do);
- Thank you Adam Kennedy, for PPI, Module::Install, ORLite, Strawberry Perl, for authoring/maintaining over 200 modules, and for being such a nice and enthusiatic person overall;
- Thank you Kartik Thakore, for taking upon yourself the weight of the SDL Perl project just a few months after even learning Perl (and doing a well job while at it);
- Thank you Matt Trout, for local::lib, DBIx::Class, and for bringing new life to the Perl world via the Iron Man Challenge and the Enlightened Perl Organization;
- Thank you Graham Barr, for Scalar::Util, List::Util, and all the Net::* modules;
- Thank you Cory Watson, for Chart::Clicker. I found out about it a couple years ago in Perlmonks and was blown away. Keep it up!;
- Thank you Chris Marshall, not only for PDL but also for co-maintaining the awesome Perl OpenGL project together with Bob "grafman" Free (Thanks to you too, Bob!);
- Thank you Adriano Ferreira, for Carp::Always, and for being the Brazilian author with most modules in CPAN. You're an inspiration to us all (mesmo entocado aí nas Minas Gerais... vê se aparece!!! :P)
Oh, I'll also take my time today to use the perlthanks tool and say thanks to all the nice people who help with perl itself. None of this would be here if not for you guys... Thanks!
Friday, 16 October 2009
make a video for YAPC::Brasil 2009!
In case you haven't already heard of it, from october the 30th to November 1st, we're working hard to put forth the greatest and largest Perl-only event in the entire Latin America, celebrate the Joy of Perl among ourselves, and tempt everyone else to join us in developing the programming language that has the happiest users! Humble goals, huh? :-)
We're still learning the ropes, so we refrained from making too much international buzz about it, or inviting foreigners to come to this year's edition. This way we can improve and mature our organization, and next year provide an event of international proportions - maybe even pay for travel and expenses of some keynotes (many thanks to all sponsors who are helping us trying to stay above the red line).
Even so, we could really use your international support!
Make a short video of just a few seconds stating your name (and cpan/irc id if you have them), location, and give us a shout! Here's a standard boilerplate example:
"Hi there! This is $name, from $location, author of $foo. Welcome to YAPC::Brasil 2009, enjoy the conference!"
That alone would be amazing, but please keep in mind it doesn't have to be that short, and of course you're free to be as creative as you want in any words of motivation you guys may have for us. Let the Brazilian Perl community see for themselves that we're just part of a whole, and that Perl is used and widely supported all over the World! Hopefully we'll be able to put up a 5-10 minute long compilation to show in the conference opening ceremony.
Oh! Almost forgot! Send the video to garu at yapcbrasil dot org dot br - thanks :-)
Become a part of the YAPC::Brasil today! And maybe in the following years we'll be fortunate enough to enjoy your physical presence there as well :-)
Thanks edenc for giving this amazing video shouting idea for the event, and perigrin for reminding me to blog about it :D
And many many thanks to you, for taking the time to record and send that video to us!