Blog of Leonid Mamchenkov

You just stepped in a pile of posts.

Entries Tagged as 'Perl'

PHP 6 - hopefully not the end of the road

Posted in All, Programming on May 19th, 2008 · 1 Comment

I’ve heard plenty of positive buzz about PHP 6 in the last few weeks.  Yes, it’s coming out.  Yes, it brings quite a few improvements, including better Unicode support, better security, and more help for larger projects through namespaces.  However, I hope that it won’t be the last PHP release, since there are so many other things that need fixing.

Here is a good overview, as compared to the best programming language ever - Perl.  But this probably reminds you of a famous Euro-English joke, no?   But I do miss sigils and proper hashes.  I’d love to see better memory management when programming objects.  I’d love to see improved database interfaces with prepared statements and database abstraction layer.  I would really welcome a cleanup in function names and return values. I … I … I … I hope that PHP 6 is not the end of the road, and that PHP 7, PHP 8, and PHP 9 will follow.

→ 1 CommentTags: , ,

Happy Birthday, Perl!

Posted in All on December 19th, 2007 · No Comments

My favorite (so far) programming language has been born 20 years ago.   It’s been loved and hated.  It’s been praised and damned.  It’s been complimented and criticized.  But all that doesn’t matter.  What matters is that it has been helping people all over the world to solve problems.  Tricky, boring, annoying problems.  It provided enough power to build enterprise grade applications, while still being easy and flexible enough to be the super-glue of many systems.

I’m sure Perl will still be with us in another 20 years.  I wish it to be as useful in that time, as it is now.

Thanks, respect, and best wishes to everyone who created and supported Perl, its community and tools all these years.  Happy birthday!

→ No CommentsTags: , , , , , , ,

RegExp reminder

Posted in All on February 22nd, 2006 · No Comments

I was just reminded about this small thing, which is so easy to forget - regular expressions that have markers of line start (^) and/or line end($) are so much faster than those regexps that don’t have these markers. The thing is that with line start/end marker regexp engine needs to make only one match/substution, whereas when there is no such markers, it has to repeat the match/substitution operation at every character of the string.

In practice, it’s unbelievable how much difference this can make. Especially when using complex regular expressions over large data sets.

P.S.: I understand that it is not always possible to use these markers, but I think that they can be used much more often than they are. Everywhere.

→ No CommentsTags: , , , , , ,

The answer to “Why Not Python?”

Posted in All on February 10th, 2006 · 4 Comments

Collin Park has written an article in four parts (one, two, three, and four) titled “Why Not Python?”. I’ve read through the first couple of parts and scrolled through the rest.

In all that text that passed in front of my eyes I haven’t found the answer to the question. I guess, it wasn’t actually the question after all then.

Well, in case you read asked yourself “Why Not Python?”, I’ll give one of the possible answers. Because it is too complicated. Python might do OK as the first progarmming language for those of you who want to learn programming concepts. But if you have a problem at hand that needs solving, Perl is the way to go in most of the cases.

Example. Collin Park uses the Sudoku game solver as one of the examples. Fine task. Nice one to learn how to program too. But if you just have a Sudoku game to solve (or a few for that matter), than it would be much faster to do it in Perl. Here is how.

  1. Navigate your browser to search.cpan.org.
  2. Type in “sudoku”, choose “Modules” and press “Search CPAN”.
  3. With this particular example, any module from the search result can be used. With other examples, you want really want to review the module description (one line that says what module does). So, this step is, choose the one module that seems to be appropriate for your problem.
  4. Install chosen module, by running cpan command from root shell and typing in install module::name (substitute “module::name” with the name of the module you chose in the previous step).
  5. Run perldoc module::name to see module documentation and example of used.
  6. Copy the code from SYNOPSIS are of documentation in your favourite editor.
  7. Save the file
  8. Run the script

Tada! You’re all done.

If it takes you more than 15 minutes, chances are - you are doing something wrong. Of course, your mileage may vary, but 15 minutes is somewhere near the lighthouse.

→ 4 CommentsTags: , , , , ,

Decimal to binary convertion in Perl

Posted in All on January 26th, 2006 · 3 Comments

This is a simple thing, but when you need it - you need it. There is no need in implementing a function that does or looking for a module at CPAN. All you are looking for is already there.

#!/usr/bin/perl -w

use strict;

# Get the number from the command line or use default.
my $number = shift || 42;

printf "%b\n", $number;

You might want to refresh you memory of printf or sprintf by flipping though the manual pages.

P.S.: 42 decimal = 101010 binary. Is it cool or what?

→ 3 CommentsTags: , , , , , , ,

Advertisement

  • Advertise at mamchenkov.net
  • Linux Weekly News
  • Flickr