Joy, from Perl
December 19, 2010
I've recently started using Perl for text wrangling instead of PHP -- it started
after much of my PHP included a lot of preg_replace and preg_match calls, which
got me wondering...
December 19, 2010
There's a certain satisfaction I get from perl that I don't really get from other languages. There's something about the density that makes it quite readable, at least for the author. Here's a script I wrote to automatically add a new build configuration, based on an existing build configuration, with some modifications, to a given .dsp (VC6 project file):
#!/usr/bin/perl $sp = "Win32 Release"; $np = "Win32 Nitpicker"; $spd="Release"; $npd="Nitpicker"; $spdir="/Release/"; $npdir="/Nitpicker/"; $libfile = "../../nitpicker/libcmt_nitpick.lib"; while (<>) { chomp; s/\r$//; s/\n$//; print $_ . "\r\n"; if (/^!ELSEIF .*$sp".*$/ || /^!IF .*$sp".*$/) { s/^!IF/!ELSEIF/; s/$sp/$np/; @nc = ($_); while (<>) { chomp; s/\r$//; s/\n$//; if (/^!/) { my $tmp=$_; foreach (@nc) { s/$spd/$npd/g; s/$spdir/$npdir/g; if (/^# ADD BASE CPP/) { s/\/Z\S *//; s/\/YX *//; s/\/FR *//; s/\/FD *//; s/$/ \/FR \/FD \/Zi/; } if (/^# ADD CPP/) { s/\/Z\S *//; s/\/M\S *//; s/\/O\S *//; s/\/FR *//; s/\/FD *//; s/$/ \/FR \/FD \/Zi \/MT \/Ot \/Og \/D "DEBUG_TIGHT_ALLOC"/; } if (/^# ADD LINK32/) { s/^# ADD LINK32 /# ADD LINK32 $libfile /; s/\/debug *//; s/\/out:/\/nodefaultlib:"LIBCMT" \/out:/; s/$/ \/debug/; } if (/^# ADD BASE LINK32/) { s/\/debug *//; s/\/map *//; s/\/dll /\/dll \/debug /; s/$/ \/fixed:no/; } print $_ . "\r\n"; } print $tmp; last; } print $_ . "\r\n"; push(@nc,$_); } } if (/^!MESSAGE.*$sp".*$/ || /^# Name ".*$sp" *$/) { s/$sp/$np/; print $_ . "\r\n"; } }In case anybody is interested, Nitpicker is something we've been working on that is similar to Electric Fence or other memory debuggers, but better suited for our workflow/design/etc. We'll probably GPL it once it matures.
Posted by Tale on Mon 20 Dec 2010 at 01:22 from 77.168.115.x
Posted by Will on Sat 01 Jan 2011 at 01:50 from 70.173.150.x
Posted by Will on Sat 01 Jan 2011 at 01:51 from 70.173.150.x
Posted by Justin on Sat 01 Jan 2011 at 10:52 from 74.66.229.x
Posted by Anonymous guy also learning PERL on Sun 30 Jan 2011 at 18:29 from 68.204.112.x
Posted by Justin on Fri 04 Mar 2011 at 17:21 from 74.66.229.x
Add comment: