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?
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).
Update: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); }
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
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: RE: pack / unpack woes
by davorg (Chancellor) on Aug 24, 2000 at 17:54 UTC | |
RE (2): pack / unpack woes
by agoth (Chaplain) on Aug 24, 2000 at 18:00 UTC | |
by davorg (Chancellor) on Aug 24, 2000 at 18:05 UTC | |
by merlyn (Sage) on Aug 24, 2000 at 18:37 UTC | |
pack / unpack woes no longer
by agoth (Chaplain) on Aug 24, 2000 at 21:26 UTC |
In Section
Seekers of Perl Wisdom