Miscellaneous

This page is a collection of miscallenous items which aren't large enough to warrant a page of their own and an entry in the main index. All code on this page is offered into the public domain; credit would be appreciated (but is obviously not required) if you use it for anything.


Perl Wordwrap

I finally got wordwrapping in Perl down to one line. Here it is:
$str=~s/(?:^|\G\n?)(?:(.{1,$width})(?:\s|\n|$)|(\S{$width})|\n)/$1$2\n/sg;
$width is the width to which you want to wrap; $str is the variable containing the existing text. If you want to make it even less readable, rename $width to $w or something else short and confusing.

Bored? Try to make it shorter!


CD Information Extractor

This is an improved version of the script found in the CD-Writing HOWTO to extract information such as the Author and Application from a CD. I sent a copy to the HOWTO author quite awhile ago, and never heard back from him, so I'm putting a copy here to make it available somehow.
#! /bin/sh

if [ "$1" = "" ]
then
    RD="/dev/cdrom"
else
    RD=$1
fi

for i in 32768,7,'      ' \
         32776,32,System  \
         32808,32,Volume  \
         32958,128,Volset \
         33086,128,Publsh \
         33214,128,Prepar \
         33342,128,Applic \
         33470,37,Copryi  \
         33507,37,Abstra  \
         33544,37,Biblio  \
         33581,16,'      '\
         33598,16,'      '\
         33615,16,'      '\
         33632,16,'      ' 
do
    old_IFS="$IFS"
    IFS=","
    set -- $i
    IFS="$old_IFS"
    OFFSET=$1
    LENGTH=$2
    NAME=$3
    echo "$3:`dd if=$RD bs=1 skip=$OFFSET count=$LENGTH   2> /dev/null`#"
done