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

In reply to Re: How do you stay motivated? by ady
in thread How do you stay motivated? by Marza

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.