in reply to Abritrary multiple spaces as delimiter

A simple regex won't work, as it would have to know the difference between "two spaces between words" and "two spaces at the end of the first part". You could either claim that "two or more spaces" delimit the items, but that will fall down as soon as you have one item that has the maximum allowed length. You could use a limited-length match like the following:

# 122 Genesis Chamber Mark Tedin A +U $string =~ /^(\d+)\s{2,}(.{28})(.{26})(.)\s+(.)$/;

But that is a very tedious way of constructing and using a regular expression when unpack can do the same:

my ($num,$title,$author,$flag1,$flag2) = unpack "A8A27A26A7A",$str;

Replies are listed 'Best First'.
Re^2: Abritrary multiple spaces as delimiter
by Aristotle (Chancellor) on Mar 15, 2004 at 10:44 UTC

    You're slurping the padding into the values.. do you really want to? Also, a few more spaces help make things pleasing to the eye:

    my ($num, $title, $author, $flag1, $flag2) = unpack "A7 x1 A27 x1 A25 x1 A1 x5 A1", $str;
    Actually I'd probably write a simple subroutine such that I could say
    unpack_fields( $str, \my $num => 7, padding => 1, \my $title => 27, padding => 1, \my $author => 25, padding => 1, \my $flag1 => 1, padding => 5, \my $flag2 => 1, );

    This also clearly documents the data format.

    Update: see Yet another unpack wrapper: flatfile databases with fixed width fields.

    Makeshifts last the longest.