Future Perl

This is mostly stuff I’ve gathered from this talk and updated slightly. First off, have you ever tried to teach a programmer perl? I have. Note this: sub foo { my ($self, $bar,$baz) = @_; #... } # or often sub station { my $self = shift; #... } The following is more palatable to most coders (also I like it better:) use Method::Signatures::Simple; method foo($bar, $baz) { #... } method station { #...

Posted Thu, May 7, 2009

Flight of the Conchords live

I’ve decided that seeing a concert warrants a blog post, and that a concert blog post can fill in for an Album of the Week post. If I pay the money to see a concert (typically more than the cost of a CD) I probably like the band that much :-) With that in mind I present to you my most recent concert: The Flight of the Conchords. You’ve probably already heard of Flight of the Conchords.

Posted Thu, May 7, 2009

Glad to be part of the Perl Community

I’ve mentioned this in at least one previous post before, but it bears repeating. First off, here’s some context for the varied information I am about to throw out at you, dear reader. I keep in touch with both the Ruby and Rails worlds because I think they have some really good ideas. Recently there was a conference session about CouchDB. I read the slides and I was impressed. CouchDB is cool stuff!

Posted Wed, May 6, 2009

WebCritic: standalone version

Ok, you guys asked for it. I have updated WebCritic to be a lot leaner and meaner. Get the new version at the same great place. It now runs entirely in it’s own lightweight server. No apache or mod_perl needed. It now uses CGI::Application::Server. It no longer uses CGI::Application::Dispatch, as my end goal no longer requires it. CAS fills the gap that CAD did for me. I also removed all of the lines that needed perl 5.10 because I wasn’t actually using any perl 5.10 features.

Posted Tue, May 5, 2009

Moose makes Perl OO Sexy!

We should have all heard of Moose by now as a great way to do OO with Perl. While I was working on WebCritic I decided that it would be a good idea to hook my OO stuff up Moose style. I figure that even if I were to just write code and then disappear I might as well write 2009 code instead of 1999 code so that if it ever gets copied it will bless the copier instead of curse them.

Posted Fri, May 1, 2009

Testing: Way Cool!

When I was writing WebCritic I decided that the code was small and simple enough that it would be a great candidate for me to figure out how to set up automated testing for the whole stack (except for the javascript.) This is something that I’ve wanted to do at work for a long time but I feel bad spending time figuring out stuff like this on the customer’s dollar. I already had Perl Testing: A Developer’s Notebook and I figured I’d use it to get a start.

Posted Thu, Apr 30, 2009

PerlCritic for Web Developers

I like to continually move towards perfection in my code. perlcritic is a tool based on the book Perl Best Practices by Damian Conway. It’s basically lint for perl. perlcritic is fine as it is if you spend all day on the console, but I usually spend my whole day in Firefox and vim. The only use for my console is checking in source and using irssi. There are a few other things I use the console for, but the point remains, I spend more time in Firefox than I do in the shell.

Posted Wed, Apr 29, 2009

Hey guys! You should blog too!

Check it! Ok that article is really long. Here’s the breakdown. Basically Matthew S Trout, the main guy who makes DBIx::Class, made a similar observation as other people. More specifically, Perl people don’t blog enough. With that in mind Mr. Trout gives some compelling reasons to start! So read the article. Also: lots of things are coming out lately! Ubuntu 9.04 just got pushed to my laptop, and my phone is gonna get updated from 1.1 to 1.5 (read: on screen keyboard!) in less than two weeks!

Posted Fri, Apr 24, 2009

Perl::Tidy: annoying facts

So I was trying to use perltidy programmatically, that means using Perl::Tidy. Basically I wanted to use an existing .perltidyrc along with the backup option. That is, instead of making a new file with .tdy at the end, replace the original and back it up to .bak. So after reading the docs I figured that this should work: use Perl::Tidy (); use File::Spec; my $file = File::Spec->catfile( $dir, $filename ); Perl::Tidy::perltidy( source => $file, argv => '-b', perltidyrc => $perltidyrc, ); Unfortunately that just doesn’t work.

Posted Fri, Apr 24, 2009

Vim Tip of the Day

Every now and then I want to run a given vim command on a bunch of lines. In the past I would have either executed the command and then pressed j. (Hi J-Dot!) to go down and repeat the command. Or if the command were more complex I would have used a macro and done it over and over with @@. Well, for simple stuff on a range there is an easier way!

Posted Thu, Apr 23, 2009

Why CPAN is Awesome

Have you ever written a server? It’s kinda fun! Yes, I’m a nerd. Anyway, I learned the easy way and the hard way to make a server in Perl yesterday. Here’s the easy way: #!/usr/bin/perl use strict; use warnings; use feature ':5.10'; use Socket; use Carp; use constant PORT => 7890; use lib '../lib'; use WebCritic::Critic; my $dir = shift; my $port = shift || PORT; my $proto = getprotobyname 'tcp'; # create a socket, make it reusable socket SERVER, PF_INET, SOCK_STREAM, $proto or croak "socket: $!"; setsockopt SERVER, SOL_SOCKET, SO_REUSEADDR, 1 or croak "setsock: $!"; # grab a port on this machine my $paddr = sockaddr_in( $port, INADDR_ANY ); # bind to a port, then listen bind SERVER, $paddr or croak "bind: $!"; listen SERVER, SOMAXCONN or croak "listen: $!"; say "SERVER started on port $port "; my $client_addr; my $critic = WebCritic::Critic->new({ directory => $dir }); while ( $client_addr = accept CLIENT, SERVER ) { # find out who connected my ( $client_port, $client_ip ) = sockaddr_in($client_addr); my $client_ipnum = inet_ntoa($client_ip); my $client_host = gethostbyaddr $client_ip, AF_INET; # print who has connected say "got a connection from: $client_host", "[$client_ipnum] "; # send them a message, close connection say CLIENT $critic->criticisms; close CLIENT or croak "couldn't close connection!

Posted Thu, Apr 23, 2009

Album of the Week: Anywhere I Lay My Head

This week’s Album of the Week is Anywhere I Lay My Head by Scarlett Johansson. The album is comprised of Tom Waits covers done by Johansson. According to my friend Neil and also Internet, Dave Sitek, also made quite the impression on the album as a whole. The main impression one gets from the album is it’s muddled sound. It’s as if Johansson is singing from the bottom of a lake or something.

Posted Wed, Apr 22, 2009

More Tools Monday

So I am working on a new way to use perlcritic, and one of the things I’d like perlcritic to check for is a correctly formatted file. Unfortunately the integration between perlcritic and perltidy goes something like this: Tidy the file with perltidy Give vague error if tidy file != original file That’s fine until you discover that = signs get aligned and apparently you cannot turn that feature off. That means that my code gets marked sketch if I don’t align my = signs.

Posted Tue, Apr 21, 2009

Post Conference Friday Toolchain

Today at work I put to use a lot of the stuff that I learned at the conference this week. The first thing I did was install JSLint Multi. I already use Yahoo! Widgets for the weather and an analog clock, so it wasn’t a big deal to install some widget. My biggest problem with JSLint is that it’s hassle city to run. Part of that had to do with my own lack of knowledge about how to use it.

Posted Sat, Apr 18, 2009

Ext Day 3

The end! Ok not quite. So this was the last day of the conference. It was shorter than the other days and most of us had to checkout anyway. Still exciting! First off we got an awesome demo of the Designer. It looks like it will be extremely useful for exploring the framework and playing with layouts. You can edit multiple components at once, as if it were an IDE. You can even load data into grids on the designer.

Posted Fri, Apr 17, 2009

Ext Day 2, Part 2

Ok, the next session I went to on Day 2 was the session on Refactoring. Refactoring is one of the few high quality buzzwords that I hear regularly, so I was excited to hear what the talk would go over. It was very much Ext specific, but the final changes to the component that we “Extified” were amazing. First off, what does it mean to Extify a component? The comp needs to fit into the Component Model, which is mostly a lifecycle issue.

Posted Fri, Apr 17, 2009

Ext Conference Day 2

Enjoy day 2: First off was the Ext 3 Release. They gave some interesting history (Ext 1.0 was released exactly 2 years ago today!) And then mentioned a few features of Ext 3. Mainly it was about Ext.Direct and how it is a solution for communication to/from the server that is apparently a need in the community. I hope to use it myself; but we’ll have to see based on the spec.

Posted Thu, Apr 16, 2009

Ext Conference, Day 1

For the benefit of my memory, my coworkers, and the rest of the intarwub, I am posting my expanded notes on the Ext Conference 2009. They are supposed to put up slides and video, so hopefully blog posts won’t be a major resource, but we’ll see. I must give my impressions of things only barely related to the conference before I get into real content though. We are at the Ritz-Carlton, which is nice.

Posted Wed, Apr 15, 2009

Vim Feature of the Day

We all know programmers who, when they need to copy/paste more than one thing, just use a temporary window to keep track of the copied data. Well vim has that feature solved. First off, we have multiple copy/paste buffers, known as registers. So I can copy and paste three different things into three different registers. To copy a line to register a, use “ayy. Then to paste that line you would use “ap.

Posted Sun, Apr 5, 2009

Introducing SillyString: fix the past!

So in the project we are doing at work right now the customer has a fairly old dataset. Old enough that it originally was impossible to properly capitalize all of your words. I do a search and get a list of customers: AMERICAN AIRLINES SOUTHWEST AIRLINES A.O.G. L3 COMMUNICATIONS ... Why are you yelling at me?! I want to say. Yesterday I had 30 minutes left in the day and I figured that I might as well do something that would make me feel good.

Posted Thu, Apr 2, 2009

DBIx::Class: A Love Story

Until recently most of the work I have done with DBIC has been very basic. I made a lot of simple classes, done some basic searches, paginated, and that was more or less it. The only thing in there that is really a major change from vanilla DBI was the pagination. Oh the glory of automatic pagination! Well, recently I have been doing more complex things, and let me tell you, it has been a joy!

Posted Wed, Apr 1, 2009

AWOL

I’m sorry that I’ve neglected this blog so much the past couple of weeks. I will give excuses promptly, and then I will immediately follow that with another post that you will hopefully find of value :-) So I was fairly sick this week and that really killed my output. It’s hard to pursue what you love when you don’t even feel alive. Turns out a lot of my friends got sick around the same time, so I image that something is going around.

Posted Sat, Mar 28, 2009

Album of the Week: Furr

Furr by Blitzen Trapper is the Album of the Week. This post (as well as 2-3 others) should have been done earlier in the week, but I was a little swamped. Sorry if you were on the edge of your seat :-P So Furr has definitely been my favorite album this week. I can tell because Last.fm tells me I have listened to it ELEVEN TIMES in the past 7 days.

Posted Sat, Mar 21, 2009

Implementing map with Perl 6 and Perl 6

Hopefully everyone reading this blog knows the function map. Map maps one array onto another with a simple function. For example, if I had a list of names at my old school and I wanted a list of emails I could do something like this: my @names = ('frew schmidt', 'bob barr', ); # etc... my @emails = map { s/\s+//; "$_\@letu.edu" } @names; I think that’s pretty great. I thought it would be cool to reinvent the wheel and implement map in Perl 6.

Posted Mon, Mar 16, 2009

Perl 6: Explained!

I was hoping to work on the setting for Rakudo some today, but it just wasn’t happening due to my own inferiorities. I decided instead to try to read some of the setting code so that I can be less inferior in the future. I hope you enjoy learning some Perl 6! First we’ll start with a simple one: Str.lcfirst. our Str multi method lcfirst is export { self gt '' ??

Posted Fri, Mar 13, 2009

Perl Tutorial 2!

Another tutorial posted here. This goes over functions, references, regular expressions, and perl’s case statement (given/when). Enjoy!

Posted Thu, Mar 12, 2009

Perl 2

Station Teammates, First and foremost, functions, or as perl calls them, subroutines. (I don’t think there’s a difference. If there is, let me know). Here’s the syntax: sub_ex.pl #!/usr/bin/perl use warnings; use diagnostics; use strict; sub frew { print "hello world!\n"; } frew; Obviously not very useful, nor is it a very good sub name. Oh well, you get what you pay for, right? Ok, one thing you will probably notice immediately is that in perl you don’t have parameter definitions like in almost every other language you have ever used.

Posted Thu, Mar 12, 2009

Album of the Week: Brave

Brave by Marillion is this weeks Album of the Week. Before I get into specifics I need to tell a story about how I got into Marillion… I found out I loved prog music because of Transatlantic. Marillion’s Pete Trewavas is one of the members of Transatlantic. I checked out all of the other band member’s groups, but I never did check out Marillion (as in order a CD.) One day I was in the thrift store and I happened upon a Marillion album (Seasons End) It was surprisingly good and I bought up a few more albums (Misplaced Childhood) Anyway, I just cannot believe that I found music that excellent at a thrift store.

Posted Thu, Mar 12, 2009

Happy Purim!

Hello everyone! Hopefully you know that today (March 9-10, starting and ending at sundown) is the holiday of Purim! I just want to mention that the best way to celebrate Purim (we did this at school) is to read the entirety of the book of Esther out loud, cheering for Mordecai (or Esther, but not both,) and booing at Haman, and each time you cheer or boo, you take a drink.

Posted Tue, Mar 10, 2009

Git Workflow for Rakudo

I just posted a workflow for Git on the Rakudo Wiki. Hopefully it works well and helps people use Git and work on Rakudo. Enjoy!

Posted Tue, Mar 10, 2009

Ghetto: Your Solution for Workarounds™

I like to make playlists. But I also reorganize my music something like once or twice a year. Because of that my playlists get broken as they are really just lists of filenames. This past summer I wrote some code in ruby that would find files with the same basename but ignore the directory structure, and reconstruct playlists from that. It worked perfectly except every now and then I would get a live version or two.

Posted Sat, Mar 7, 2009

Reduce: what exactly did it do?

Did you do a reduce and get confused about how it got the final answer? Do you just want to see the computer write out it’s work? Check it: (1,2,3).reduce({ $^a / $^b }) RESULT«0.166666666666667» (1,2,3).reduce({"($^a / $^b)"}) RESULT«"((1 / 2) / 3)"» (1,2,3).reduce({ $^b / $^a }) RESULT«1.5» (1,2,3).reduce({"($^b / $^a)"}) RESULT«"((3 / 2) / 1)"» How cool is that?

Posted Sat, Mar 7, 2009

mod_perl: For Your Health!

You may have wondered why I had the slight delay in posts this week. I had a good reason: we switched one of our major products from IIS to Apache! In general it was a fairly painless process. The details are documented in my previous post, Migrating from IIS to Apache. There was one hitch though… We have an autocomplete field that needs to be pretty snappy. For IIS we just installed ActivePerl and named the file autocomplete.plex and it was good.

Posted Sat, Mar 7, 2009

Album of the Week: Tallahassee

Tallahassee is the album of the week. This was the first of the higher quality albums put out by The Mountain Goats. If I were to describe The Mountain Goats concisely I would probably say they are depressing, prolific, and well-read. I think the lyrics of this band really need to be put at the front stage, so check out these samples: From Southwood Plantation Road: All night long you giggle and scream Your brown eyes deeper than a dream I am not going to lose you We are going to stay married In this house like a Louisiana graveyard Where nothing stays buried On Southwood Plantation Road Where the dead will walk again Put on their Sunday best And go with unsuspecting Christian men La la la la la And from the classic No Children: I hope that our few remaining friends Give up on trying to save us I hope we come up with a failsafe plot To piss off the dumb few that forgave us I hope the fences we mended Fall down beneath their own weight And I hope we hang on past the last exit I hope it’s already too late And I hope the junkyard a few blocks from here Someday burns down And I hope the rising black smoke carries me far away And I never come back to this town Again in my life I hope I lie And tell everyone you were a good wife And I hope you die I hope we both die Notice a theme?

Posted Sat, Mar 7, 2009

New Tutorial!

Ok, so when I was in school, I trained some guys on perl (and other things) over the summer via email. I decided to resurrect the tutorials so more people could use them. The idea is that they are good for programmers because they don’t explain the basics of what arrays are etc. Anyway, hope someone digs it! Perl Tutorial 1. Have fun!

Posted Thu, Mar 5, 2009

Perl 1 (and a little bit of Linux)

Hello friends! This is the part where you learn the basics of Perl! I am not going to tell you about where it came from or any of that history stuff. If you want, all that is on Wikipedia. What I AM going to tell you is how to program in it. I highly suggest you try out all of this code and play with it a little bit so that you understand it.

Posted Thu, Mar 5, 2009

Perl Tutorials

Perl Tutorial 1 Perl Tutorial 2

Posted Thu, Mar 5, 2009

Reverse Polish Notation Calculator in Perl6++

Apparently Patrick Michaud, pumpking of rakudo, read my post yesterday and he came up with an even better solition! I’d read his post if I were you, but here was the code he got it down to (after adding the R meta op :-) ): my %op_dispatch_table = { '+' => { .push(.pop + .pop) }, '-' => { .push(.pop R- .pop) }, '*' => { .push(.pop * .pop) }, '/' => { .push(.pop R/ .pop) }, 'sqrt' => { .push(.pop.sqrt) }, }; sub evaluate (%odt, $expr) { my @stack; my @tokens = $expr.split(/\s+/); for @tokens { when /\d+/ { @stack.push($_); } when ?%odt{$_} { %odt{$_}(@stack); } default { die "Unrecognized token '$_'; aborting"; } } @stack.pop; } say "Result: { evaluate(%op_dispatch_table, @*ARGS[0]) }"; Brilliant!

Posted Tue, Mar 3, 2009

Why Perl Doesn't Need IPL: redux

Jeff Atwood claims that comments are a required ingredient for a blog. How true! There have been some comments recently on my original post about an interactive perl shell. My post mostly centered around writing one liners with your regular shell. Well, brunov replied and mentioned Devel::REPL, which is excellent! It has all kinds of great features and really does everything that you would expect a modern language shell to do.

Posted Tue, Mar 3, 2009

Making Rakudo more interactive

This doesn’t really make rakudo interactive, it just gives you history, but that’s pretty nice! ledit ./perl6 ledit is in apt, so if you have ubuntu you can just install it with sudo aptitude install ledit. Very nice!

Posted Sun, Mar 1, 2009

Are You Experienced?

“For what it’s worth, ± does happen to be in Latin-1, and therefore officially fair game for Standard Perl.” –Larry Wall, on adding ± as some form of operator to perl6.

Posted Sat, Feb 28, 2009

Perl 5 to Perl 6: a Reverse Polish Notation Calculator

I did this because of the excellent Higher-Order Perl. Here is the Perl 5 code: #!/usr/bin/perl use strict; use warnings; my $op_dispatch_table = { '+' => sub { my ($stack) = @_; push @$stack, pop(@$stack) + pop(@$stack); }, '-' => sub { my ($stack) = @_; my $s = pop(@$stack); push @$stack, pop(@$stack) - $s; }, '*' => sub { my ($stack) = @_; push @$stack, pop(@$stack) * pop(@$stack); }, '/' => sub { my ($stack) = @_; my $s = pop(@$stack); push @$stack, pop(@$stack) / $s; }, 'sqrt' => sub { my $stack = shift; push @$stack, sqrt(pop(@$stack)); }, }; my $result = evaluate($op_dispatch_table, $ARGV[0]); print "Result: $result\n"; sub evaluate { my $odt = shift; my @stack; my ($expr) = @_; my @tokens = split /\s+/, $expr; for my $token (@tokens) { if ($token =~ /\d+$/) { push @stack, $token; } else { if (my $fn = $odt->{$token}) { $fn->(\@stack); } else { die "Unrecognized token '$token'; aborting"; } } } return pop(@stack); } And here is the Perl 6: #!/home/frew/personal/rakudo/perl6 my %op_dispatch_table = { '+' => sub (@stack) { @stack.push(@stack.pop + @stack.pop); }, '-' => sub (@stack) { # this should probably be: # @stack.push(@stack.pop R- @stack.pop); my $s = @stack.pop; @stack.push(@stack.pop - $s); }, '*' => sub (@stack) { @stack.push(@stack.pop * @stack.pop); }, '/' => sub (@stack) { # this should probably be: # @stack.push(@stack.pop R/ @stack.pop); my $s = @stack.pop; @stack.push(@stack.pop / $s); }, 'sqrt' => sub (@stack) { @stack.push(@stack.pop.sqrt); }, }; sub evaluate (%odt, $expr) { my @stack; my @tokens = $expr.split(/\s+/); for @tokens -> $token { if $token ~~ /^\d+$/ { @stack.push($token); } else { if my &fn = %odt{$token} { &fn(@stack); } else { die "Unrecognized token '$token'; aborting"; } } } return @stack.pop; } say "Result: { evaluate(%op_dispatch_table, @*ARGS[0]) }"; Usage: ./calc.pl “5 6 +” The main differences to notice are sigil invariance, subroutine signatures, and method instead of function syntax.

Posted Sat, Feb 28, 2009

OLOTD

noglob zmv -W */^.flac */.flac I just ripped a bunch of music into flac and I forgot to add .flac to the end of the files until I was mostly done. If you are using zsh (and you load the zmv module) the above line will rename all files that do not end in .flac to whatever they used to be, but with .flac at the end. excellent.

Posted Fri, Feb 27, 2009

Javascript scope

One of my least favorite things about javascript is scope management. In most languages scope is quite clear; if you defined a variable previously and “higher up” in some kind of scope stack, you can access it. And furthermore, this always refers to the current object. That’s not quite true for javascript, because javascript is different than (almost) any other programming language you have ever used. You don’t like monkeypatching? Bummer.

Posted Thu, Feb 26, 2009

Album of the Week: To Watch the Storms

This week’s AOTW is To Watch the Storms by Steve Hackett. I first heard of Steve Hackett (and also this album) in a sampler from InsideOut. I remember listening to the sampler and being blown away by both the Hackett song and the Flower Kings song. I later ordered this album and have consistently been impressed by the quality of the album. But quality is not all that it takes to make a great album.

Posted Tue, Feb 24, 2009

Higher-Order Perl

One thing that I love about reading good programming books (maybe even good Perl programming books) is the humor instilled in them. Tonight I decided to start reading Higher Order Perl (which you can get free here!) Here is a selection from the frontispiece: … Hardly anyone wants to listen to Lisp programmers. Perl folks have a deep suspicion of Lisp, as demonstrated by Larry Wall’s famous remark that Lisp has all the visual appeal of oatmeal with fingernail clippings mixed in.

Posted Mon, Feb 23, 2009

Least Favorite Features

brian d foy (author of numerous perl books) asked this question on Stack Overflow: “What are five things you hate about your favorite language?” I figured that since I am trying to bring perl 6 to fruition (note: I’ve only written tests, so I am not very good at helping so far) I would pick perl 6 as my favorite programming language. Here was my answer: I’m going out on a limb since I can’t really use it full time, but I’ll try anyway!

Posted Mon, Feb 23, 2009

Paranoid Deletion in DBIx::Class

In the most well designed databases that I’ve used we never really deleted anything from the database. We would just mark a field as deleted and then just make sure to filter out the deleted data when we searched and it was all groovy. You could easily readd the item and you never truly lost much data. Well, now that I am using an ORM I’d like a similar feature in my current database and I’d like it to be as automatic as possible.

Posted Tue, Feb 17, 2009

Rakudo Autobuilder

First off, if you did not already know, rakudo is the first implementation of perl6. There is no plan for an official Perl 6 implementation, so we have to give this implementation a name other than perl6. Anyway, I know that you are all working diligently on perl6 like I am, so I know that you are having trouble because you have to rebuild parrot and rakudo which is kindav a hassle.

Posted Mon, Feb 16, 2009

The Beginning of a Roles Based Authorization System for Perl

Today I was talking with a friend about the stuff we are doing at work and I mentioned to him how I was planning on doing the authorization. Since I had only thought about it at that point I didn’t even know if my idea was valid Perl syntax, let alone a feasible idea. But enough with the backstory, how about some real information. Let’s assume that we have a webpage that lets you read user data and write user data.

Posted Fri, Feb 13, 2009