Using perl for in-place search-and-replace

To make a long story short: $ perl -pi.bak -e ‘s/this/that/g’ `find inhere/ -type f` This will create backup files. Yes, you want them. Really. Otherwise, in particular under Windows, errors like this may show up: Can’t do inplace edit on inhere/example.c: Permission denied. This may look harmless, but in fact the target file ends [...]

fork(), wait(), timeout and the return codes in Perl

The mission What I really needed was a proper timeout for a certain chunk of Perl code. There is alarm() of course, but one has to watch out with certain commands that cancel it (sleep() and other less expected functions). The script also uses “system()” to run processes outside the native Perl domain, so getting [...]

A perl script sending mails for testing a mail server

Just set up your mail server? Congratulations! Now you should test it. In particular, check if it relays mails to other servers and if the response time is reasonable. Here’s a script for doing the testing. Just edit the arguments to send_mail() to match your setting. #!/usr/bin/perl use warnings; use strict; use Net::SMTP; send_mail(’127.0.0.1′, # [...]

Perl script rectifying the encoding of a mixed UTF-8 / windows-1255 file

Suppose that some hodge-podge of scripts and template files create a single file, which has multiple encoding of Hebrew. That is, both UTF-8 and windos-1255. If the different encodings don’t appear in the same lines, the following script makes it all UTF-8: #!/usr/bin/perl use strict; use warnings; use Encode; binmode(STDOUT, “:utf8″); while (defined (my $l [...]

My script for removing trailing white spaces from files

Git has this thing about trailing white spaces in source files, for good reasons. Somehow it looks like there isn’t a widely spread utility for cleaning up a lot of files in one go. On the other hand, there are plenty of them out there, but none met my needs. So I wrote yet another [...]

Perl-only CRC32 function (without C code)

It may look like a stupid idea, since the CRC32 has been implemented in some Perl modules which can be downloaded from CPAN. But all functions I found involve an XS part, which essentially means that a compilation of C code has to take place during the installation. In other words, these modules can’t be [...]

Canonizing PCAD netlist files

OK, so the board designer just sent me an updated schematics of the design. Are there any changes? Comparing the schematics itself is hopeless. So I’ll compare the PCAD netfiles (those with a .NET extension). I mean, they are simple text files, after all. The problem is that Orcad feels free to change the order [...]

Enumerating FSM states automatically for Verilog with Perl

Having a pretty large state machine, I wanted the states enumerated automatically. Or at least not do the counting by hand. I mean, doing it once is maybe bearable, but what if I’ll want to insert a new state in the future? So what I was after is something like module main_state #(parameter ST_start = [...]

Catching the transient cookies: Log in, then crawl

The old way Sometimes all you need is a quick crawl within a site, which requires to log in first. There are two main techniques I can think about: One is to POST the login form with your script, and get the necessary cookie setting. The second is to login manually with a browser, and [...]

Using Perl to map FPGA pins from a board design to UCF pin constraints

One of the things I try to avoid as an FPGA engineer, is to manually configure the pin constraints (in the UCF file) in order to tell the tools which FPGA pin is connected to what. Not only is this extremely boring, but I also think that getting it done right (at the first go) [...]