Well, today's the day we play that silly game with the clocks. So, what to do with that extra hour? How about play around with a dot Perl?
That thread happened last week and it also showed up on $reddit, but somehow I missed it. Of course, as soon as I saw it, I had to try it!
mkdir perlgit cd perlgit git clone git://perl5.git.perl.org/perl.git cd perl git checkout -b leonbrocard/dot origin/leonbrocard/dot sh Configure -de -Dusedevel -Dprefix=$PERLBREW_ROOT/perls/perl-5.15-dot make make test make install
Wait, how come all the executables have the api_version
on the end?
cd $PERLBREW_ROOT/perls/perl-5.15-dot/bin/ for file in *5.15.4; do ln $file $(echo $file | sed 's/5.15.4$//') done
Alrighty then, let's try it!
$ perlbrew switch perl-5.15-dot $[ used in numeric lt (<) (did you mean $] ?) at /loader/0x17f9100/App/perlbrew.pm line 1047.
Huh. I guess perlbrew doesn't like a name that doesn't end in a version number? No matter. Pressing on.
$ perl -E 'say "con" ~ "cat"' syntax error at -e line 1, near ""con" ~" Execution of -e aborted due to compilation errors.
Rats! The -E flag didn't enable the new dot feature.
$ perl -Mfeature=dot -E 'say "con" ~ "cat"' concat
Hooray! Okay, how about that dot? Let's try using an OO module. Here's a little script that uses HTTP::Tiny to grab the Futurama quote from the Slashdot header (essentially, it's doing curl -s -I slashdot.org | grep 'X\-\(Fry\|Bender\)'
).
#!/usr/bin/env perl use v5.15.4; use warnings; use feature qw(dot); use HTTP::Tiny; my $url = shift // 'http://slashdot.org/'; my $response = HTTP::Tiny.new.request('HEAD', $url); # Oops! Dot doesn't interpolate. # # die "Error $response.{status}: $response.{reason}" # unless $response.{success}; die 'Error ' ~ $response.{status} ~ ': ' ~ $response.{reason} unless $response.{success}; my %headers = %{$response.{headers}}; foreach (qw(fry bender)) { my $key = "x-$_"; say "\u$_: $headers{$key}" if exists $headers{$key}; }
Aw, the dot didn't interpolate. I wanted to write that commented out bit, but instead I had to concatenate strings...yuck! It works, though
$ ./usedotperl.pl Bender: Curse you, merciful Poseidon! $ ./usedotperl.pl foo Error 599: Internal Exception at ./usedotperl.pl line 17.
I don't think it really looks any nicer, but it is easier to type. The thing I hate about ->
is having to type an unshifted character followed by a shifted character. I had the same complaint about comments in C in the old days (I switched to //
just as soon as I could).
Anyway, it's fun to play with! If this feature ever makes it into Perl (unlikely, given the responses on p5p), I think interpolation has to be made to work. Also, I would want both -E
and 'use v5.15;
' (or whatever) to enable dot
automatically.
Recent Comments