Articles Tagged: perl

C-Like Pointers In Perl...Oh No! April 28, 2009

Tuesday night David Lowe gave a very interesting talk at SF.pm on pack/unpack and some of the awful things you can do with them.1 We ended the meeting talking about whether you could use the pack format “P” (which packs and unpacks “a pointer to a structure (fixed-length string)”) to force poor Perl to do C-like pointer arithmetic.

David is using unpack to do a binary search of fixed width blobs of data in order to avoid unserializing it. His current (minor) bottleneck is creating the pack format string dynamically for each step in the binary search (ie, 'x' . ($record_size * $record + 1)). The math is fast, the string concatenation is relatively slow. I wondered if you could use the “P” format to avoid creating the format string on each pass and stick with simple integer arithmetic.

After a bit of hacking, it turns out this can be done. Instead of David’s very complicated:

More...

Using Par::Packer (pp) with WxWidgets on Windows June 28, 2007

After spending a considerable amount of time trying to package a Gtk2 app with pp, I decided to try a different gui toolkit, and was successful packaging a Wx app.

Again, most of this kludge is based on bug reports from Marc Lehmann regarding Gtk. Thanks Marc!

More...

Perl Tk on Cygwin June 28, 2007

Getting Perl/Tk running under cygwin seems to be a constant pain. Until the recent perl release which went to a site/5.8 directory for modules, this was something that I went through every time I upgraded perl. I think I found the secret though. Apparently they dropped cygwin support in Tk804. You need to get Tk800.025 from cpan. Make test still reports a few errors, but the installation works for me.

CPANPLUS with Local CPAN June 28, 2007

In followup to the not about how to create a local cpan repository, I figured out how to get cpanplus to use this respository. Not nearly as simple as with cpan, but once it is setup, it is a breeze. The following script does all the work.

More...

Local CPAN (mini-cpan) June 28, 2007

Found a nice module/script to keep a local copy of the cpan repository for those times when we aren’t connected to the internet.

Used cpanp to get CPAN::Mini

minicpan -r ftp://ftp.ibiblio.org/pub/languages/perl/CPAN/ -l CPAN/

From cpan use this to add the local repository. (This is a pain to do with cpanplus

o conf urllist unshift file:///home/mgrimes/CPAN/

Imagemagick and PerlMagick on Cygwin June 28, 2007

PerlMagick is another one I always struggle to install under cygwin. I have gotten it to work under cygwin 1.15.18-1. First, don’t use the ImageMagick package distributed with cygwin. Get version 5.5.7 binary, cygwin distribution originally from www.imagemagick.org but since they have moved to version 6.

Install ImageMagick into /usr/local with the following commands:

$ cd /tmp
$ tar -xvzf ImageMagick-i686-pc-cygwin.tar.gz
$ cd ImageMagick-5.5.7
$ tar -cvzf install.tgz *
$ cd /usr/local
$ tar -xvzf /tmp/ImageMagick-5.5.7/install.tgz
$ rm -rf /tmp/ImageMagick-5.5.7

More...

Lossless Rotation of JPEGs June 28, 2007

Found a very interesting tool to do lossless rotation and EXIF editing of JPEG files. Checkout jpegtran. This version is apparently a patched version of the JPEG software from IJG.

jpegtran -copy all -rotate 90 1.jpg

There is also a related tool, jhead, which can pull all sorts of interesting stuff out of JPEGs. This will extract a thumbnail which most cameras already embedded in photos:

jhead -st "thumbnails &i" *.jpg

And finally, another tool and script which can auto-magically rotate files based on the orientation info in the header.

Using Par::Packer (pp) with Gtk2 on Windows June 28, 2007

Well I haven’t completely got it working, but it is darn close. I ended up switching to WxWidgets, which will work with some coaxing. Most of this kludge is based on bug reports from Marc Lehmann. Thanks Marc!

First off, we need to create a list of all the Gtk2 files that aren’t picked up automatically by pp. I use this script to create the list and run pp. Note that I am running the script under cygwin, but I want to use the ActiveState Perl to run pp so we end up with a native Windows app. (BTW, I tried our Strawberry Perl, but it had issues with some of the dependencies due to a lack of pkgconfig.)

More...

Backing up Linux/Cygwin with rsync and perl June 28, 2007

rsync is a very powerful tool, but not always the most intuitive. Here is a Perl script that I use to backup all of my relevant files (under both Linux and Cygwin) to a remote backup machine. All that is needed is ssh, rsync and perl.

License

The contents of this blog are licensed under the Creative Commons “Attribution-Noncommercial-Share Alike 3.0″ license.