http://www.perlmonks.org?node_id=29414


in reply to pack / unpack woes

Well, I don't have a sample of your input data to play with, but it don't see the point of the pack/unpack thing. It seems to me that the following would do what you want. If it doesn't can you tell me what you're acheiving with the pack/unpack thing?
sub split_up { my @d = @{ shift() }; my @a = ($d[4] =~ /.{35}?/g); for (0..4) { $a[$_] = '' unless exists $a[$_] }; my $cust = join ',', map lc ('A', $d[0], 'WEB', '', @d[1..3], @a, @d[5..7], '', '', $d[8], '', $d[19], '', '', $d[18], ''); my $child = join ',', map lc ($d[0], @d[9..17]); return ($cust, $child); }
Update:
Well as dave pointed out (and I suggested may be the case), I totally missed the point of the pack/unpack. I looked into sprintf, but I'm not convinced it's any better than your original (I haven't tested this).
sub split_up { my @d = @{ shift() }; my @a = ($d[4] =~ /.{35}?/g); for (0..4) { $a[$_] = '' unless exists $a[$_] }; my $cu_fmt = ''; for (1, 9, 3, 60, 10, 20, 40, 35, 35, 35, 35, 35, 10, 3, 20, 20, 20, 50, 1, 1, 1, 1, 6, 6) { $cu_fmt .= "\%-${_}.${_}s," } my $cust = sprintf $cu_fmt, ('A', $d[0], 'WEB', '', @d[1..3], @a, @d[5..7], '', '', $d[8], '', $d[19], '', '', $d[18], ''); my $child_fmt = ''; for (9, 20, 20, 20, 20, 1, 1, 1, 6, 6, 6){ $child_fmt .= "\%-${_}.${_}s," } my $child = sprintf $child_fmt, ($d[0], @d[9..17]); return ($cust, $child); }

Nuance