Perl-related stuff and beyond (but not much)

Saturday, May 09, 2009

Some say Perl is ugly

Some say Perl is ugly because is uses a lot of non-alphabetical characters in its syntax. Well, I think that approach is stupid. In effect it's the same as saying that russian is ugly because it's written in cyrillic. What kind of argument is that? What about all those people who speak russian? Are they not-really-smart because they write it in cyrillic? I don't understand it. I never will. It would be okay if Perl was ugly because you have to write the for loop in some uber-complex-assembler style. Ok, that's ugly and non-trivial. On the other hand, people that object to the sigils use funny nomenclature in their programs; combination of hungarian notation and camelCase. I cannot read it. It's ugly. (Sarcasm mode turned on.)

Thursday, May 07, 2009

Extract base path

Simple solution to a Delphi task: extract base path from two paths:



#!/usr/bin/perl

# extract_base_path.pl - extract base path from two paths
# http://delphi.about.com/b/2009/05/06/delphi-programming-challenge-extractbasepath.htm
# dprelec, 2009-05-07

use strict;
use warnings;

my $path1 = '/usr/bin/perl/lib/';
my $path2 = '/usr/bin/perl/';

my @parts = split('/', $path1);
my $last = '';
my $re = join('|', reverse map { $last .= $_ . '/'; $last } @parts);

if ($path2 =~ /($re)/) {
print $1, "\n";
}