It calculates a Morris sequence of numbers. This is also called the “look and say” sequence. For example, if the first number is 1, then the second number is 11, because there is one one in the previous element. Then the next number in the sequence would be 21, because there are two ones. Etc.
(Sorry, deleted the code because it was getting all messed up, even wrapped in pre tags. It’s… here http://kaishaku.diaryland.com/090129_39.html )
Jan 28, 2009, 09:13PM PST | 0 comments
Example:
sub sum_of_list
{
my $total;
foreach(@_)
{
$total += $_;
}
$total;
}
And that will return the sum of a list of numbers. What’s friggin’ awesome about it? It works with any number of parameters. Perl’s handling of lists is awesome in this respect. You can do:
sum_of_list(1, 3, 5, 7, 9); or
sum_of_list(qw/1 3 5 7 9/); or even
sum_of_list(1..100);
So, pretty much loving it so far.
Jan 24, 2009, 01:16AM PST | 0 comments
I received my copy of Learning Perl a couple days ago. Yesterday I was cleaning out the bookshelf to make room for the lady friend’s stuff, and I find … Learning Perl. I knew I had read it before but I thought it was a library copy. At least the new one is the 3rd edition and the old one is 1st. I’m keeping them both to remind myself of my stupidity.
Jan 06, 2009, 01:15AM PST | 0 comments
Using regex! It worked and was possibly even partially non-retarded.
Dec 31, 2008, 06:17PM PST | 0 comments
Learning Perl by Schwartz & Phoenix was available on half.com for 75 cents plus shipping. I snatched it up.
Dec 27, 2008, 08:16PM PST | 0 comments
I read the Larry Wall book about 12 or 15 years ago, but it didn’t sink in permanently because I never did much scripting. Nowadays I sometimes find myself doing something where a perl script would have suited excellently, but my inexperience in perl causes me to usually write it in C or Java (as overkill as that may be).
I considered other scripting possibilities:
- JavaScript? I dig the first-class functions but it’s too web-oriented
- PHP? Suffers the same negatives
- Lisp or Scheme? Probably too theoretical for me.
So, I think I’ll have to hit the library again for that perl book.
Nov 03, 2008, 08:20PM PST | 0 comments