Archive for the 'stackoverflow questions' Category

25
Mar
09

perl headshot

Perl was the first programming language I learned. It felt great to be so productive with so few lines of code. Trying to provide code for this stackoverflow answer was pretty cumbersome. My first impression was : this is an easy task for File::Find, but it turned out I was wrong.

I may be wrong, but I think File::Find does something like this :


get a list of all files in directory passed as argument
foreach file
  call the supplied callback with the file as it's argument

Let me give you an example why this is not the desired output in this particular case, consider the following directory structure:

a/
a/first.txt
a/b/
a/b/another_file.txt
a/b/c/

So, let’s assume this is the order in which we will get the files in File::Find’s wanted callback. We first receive the “a/” directory, which we capitalize as the question asked, so, after we’re done processing, the directory’s name will be “A/”. The next arguments the wanted function will receive will be “a/first.txt”,”a/b”,”a/b/another_file.txt”,”a/b/c/”, and not “A/first.txt”,”A/b”,”A/b/another_file.txt”,”A/b/c”. If we keep getting the arguments like that, we would have to split the path, check and see if the directory name has been capitalized, and then apply the rename.

Hard, right? It would have been easier to get the files while keeping count of the renamed directories. So, after 9 revisions to my post, I gave up on perl, and I rewrote everything from scratch using ruby. I could have accomplished the same thing in perl pretty easy,and I’m not blaming File::Find for this, but, overall, I felt that the language wasn’t working with me anymore.

… so, it turns out I’m not productive in perl anymore. I’m won’t use it anymore. No more perl references, globs, hashes, arrays, contexts, objects etc. I’ve got to the point where they just get in my way, and I don’t find them cool anymore.

Good luck, Perl! And thanks!

P.S: I’m pretty confident that this is the behaviour the author of the question wanted :). The ruby code can be found on the question’s page




Blog Stats

  • 216,750 hits