in reply to How do you stay motivated?

I like to wrestle with ideas in the area of computer science, -- data structures, algorithms, different programming paradigms. I like a programming environment that supports me in this respect.

Most of my daily work these days is centered on architecture & technical design plus program development in .NET C#. That's fine for team development of enterprise applications, but it has too much OO telescope vision and syntax overload for fast and flexible data munging and prototyping. For the latter tasks i always try to squeeze in Perl at work.

To stay on tracks with Perl (even though it's pt at most 10% of my work), I enjoy following the discussions here on PM and digesting books like Effective Perl Programming and HOP. For example I recently faced a problem at work, traversing a directory hierachy, extracting and manipulating certain files. I utilized a technique described in HOP to easily and elegantly solve this task. I could have done it in C#, but it would have taken double up the time and space.

#!C:/Perl/bin/perl.exe -w # Program.. : Iterate.pl: iterate over dir.tree and prefix files with + dir-name. # Function. : Recurse from current dir; Prefix each "WrappedXml.{0,9} +\.xml" # file with immediate subdir and copy this file to curren +t/. dir. # Usage.... : Call Iterate.pl in the root of the dir tree to scan. # Ref...... : HOP Ch.4: Iterators # History.. : 040306 - Allan Dystrup, Ver.0, AND/KMD EDPI # =========================================================== use strict; use warnings; use File::Copy; ### -------------------------- Util ----------------------- sub Iterator (&) { return $_[0] } sub NEXTVAL { $_[0]->() } ### -------------------------- Iterator ------------------- sub interesting_files { my $is_interesting = shift; my @queue = @_; return Iterator { while (@queue) { my $file = shift @queue; if (-d $file) { opendir my $dh, $file or next; my @newfiles = grep {$_ ne "." && $_ ne ".."} readdir + $dh; push @queue, map "$file/$_", @newfiles; } return $file if $is_interesting->($file); } return; }; } ### -------------------------- FileMask ------------------- sub is_WrappedXml { my $file = shift; return 1 if $file =~ /WrappedXml.{0,9}\.xml/i; return; } ### -------------------------- MAIN ----------------------- my $WrappedXml_file = interesting_files(\&is_WrappedXml, '.'); print "Copying xml instances :\n"; while (defined(my $file = NEXTVAL($WrappedXml_file))) { my $newfile = $file; $newfile =~ s#/(WrappedXml.{0,9}.xml)#\-$1#i; # subst / -> - $newfile =~ s#.*/(.*)#$1#; # zap base dir print "\t$file\n\tCopy -> .\\$newfile\n"; copy("$file", ".\\$newfile") or die "Error copy: $!"; }


Best regards
Allan Dystrup