KBD

Keith Devens .com

Sunday, July 6, 2008 Flag waving
You can't do anything worthwhile without pissing somebody off. – I forget

Tag: Perl

Parents:

Daily link icon Wednesday, September 12, 2007

while(<>){...} in Ruby

Re: translate Perl diamond operator to Ruby.

Perl:

while(<>){
  ...
}

Ruby:

ARGF.each do |$_|
  ...
end

At this point I question whether I'd ever use Perl for anything again. Until now, Perl filled a niche where if the code I wanted to write would fit in 10 lines or so, and did a lot of string manipulation, I'd turn to Perl. Otherwise Python. Now I think I'll just use Ruby for everything Smiley

Daily link icon Thursday, July 27, 2006

Dumb substring behavior in C# (and Java)

Substring in C# (and Java) throw an exception if you take a substring and give it a length (or a starting position) that puts you after the end of the string. That's basically to ensure that you always get a string that's exactly the length you want? Rather than just being able to take a substring and not having to worry about it, you have to include code like the following around every single substring you ever take:

if (str.Length > 30){
    str = str.Substring(0, 30);
}

Typically when you take a substring you want to ensure that your string is no longer than a certain number of characters. I can't think of a situation that would it a good idea for the language to enforce that you can't get a string that's less than the maximum length you want instead of exactly the length you want.

On the other hand, most of the dynamic languages (PPPR) let you substring off the end of the string without worrying about it.

Daily link icon Wednesday, May 17, 2006

  1. perl.com: Perl Command-Line Options. Good reference and tutorial.

       (3) Tags: [Perl]

Daily link icon Friday, March 24, 2006

  1. Here's some quick Perl I used to unescape some form-encoded data:

    while(<>){
        s/\+/ /g;
        s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge;
        print;
    }
       (0) Tags: [Code, Perl]

Daily link icon Sunday, February 5, 2006

  1. reform - Third millenium syntax for Perl 5 OOP (via Keith). Actually reasonable OO syntax in Perl.

       (0) Tags: [Perl, Programming]

Daily link icon Thursday, November 17, 2005

  1. First monads in Perl, now monads in Ruby (via Keith Gaughan, via The Farm), both still to read.

       (0) Tags: [Monads, Perl, Programming, Ruby]
July 2008
SunMonTueWedThuFriSat
 12345
6789101112
13141516171819
20212223242526
2728293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 4 posts

Recent comments XML

Girls, please don't get breast implants

> And no, you will not be receiving​a picture.

:-(...

Keith: Jul 2, 6:05am

Javascript clone function

This is a clever way to clone an​object if you are using YAHOO UI.​Same tec...

Antonio: Jul 1, 12:47pm

I hate Norton Antivirus

Oh just one other thing norton is​great at keeping people out of your​compu...

kevin.sands: Jul 1, 12:50am

Generated in about 0.125s.

(Used 10 db queries)

mobile phone