in reply to Trimming unpack'ed strings

I probably would not do this as a one-liner. The trimming can easily be handled with map, though.

my ($catno, $desc, $pack, $min, $gst, $cost, $unitcost, $retail, $barcode) = map { s/\s+$//; $_ } unpack("A7 x2 A30 A4 A4 x13 A7 x15 A8 A8 A8 x13 A13", $_);

The call to map makes a new list from the old list after removing any trailing whitespace.

It seems like there's a way to get unpack to return an empty field. But that escapes me at the moment.

Update: as jwkrahn points out, my change shouldn't be needed because of the 'A'. I should have looked at the unpack template instead of the OP reference to needing to strip the whitespace.

G. Wade

Replies are listed 'Best First'.
Re^2: Trimming unpack'ed strings
by jwkrahn (Abbot) on Nov 05, 2008 at 22:40 UTC

    The  map { s/\s+$//; $_ } is superfluous because the  "A" format of unpack already removes all trailing whitespace.