Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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); }
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); }


In reply to RE: pack / unpack woes by nuance
in thread pack / unpack woes by agoth

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2022-05-20 15:19 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (73 votes). Check out past polls.