G'day jlope043,

You don't need to pad your lines with spaces: you can use 'A*' at the end of your template. See "perlpacktut - tutorial on pack and unpack".

I don't know this Print function that you've used multiple times. Did you mean print? Did you fail to show us a subroutine definition for &Print? Did to fail to show a module you loaded which implements a Print function? I could just assume it's a typo, propagated twelve times, and print was in fact intended; however, your expected output bears no relation to what print statements would actually output.

I don't think you really need to assign the results to that list of variables; you could proably just use the unpack result directly (see my code example below). By the way, there's another typo there: #amt3 should presumably be $amt3 (Perl will see #amt3 as the start of a comment and ignore it, and everything after it on that line).

When working with comma-separated data, you should use Text::CSV. If you also have Text::CSV_XS installed, it will run faster. You can also use this for tab-, pipe-, or other_character-separated data.

Given the number of unknowns, it's difficult to provide you with a solid solution. I will take a guess that what you want is close to something like this:

#!/usr/bin/env perl -l use strict; use warnings; use Text::CSV; my $csv = Text::CSV::->new; while (<DATA>) { $csv->print(\*STDOUT, [ map { /^\s*(.*?)\s*$/ } unpack 'A3A9A9A*' +]); } __DATA__ 123 qwe, rty 04/05/06 X 456 asd, fgh 07/08/09 XX 789 zxc, vbn 01/02/03 XXX

Output:

123,"qwe, rty",04/05/06,X 456,"asd, fgh",07/08/09,XX 789,"zxc, vbn",01/02/03,XXX

As a final piece of advice, pay more attention to what you're doing. You've been using Perl for a year or so now: it's fine that you haven't learnt about all the techniques and modules available, and we're happy to help you with that; it's most definitely not OK to post rubbish, and then state "when I run the process I get no results." — the first two responses you got[1,2] clearly show the results consisted of error messages, which you would have got too — this sort of thing doesn't fool us and doesn't help you. If you are genuinely unable to copy and paste your actual code, then say so, but at least make an effort to reproduce the real code; don't make up stories about how you ran it, along with fictitious claims about the output it produced.

— Ken


In reply to Re: Unpack and Print NEW by kcott
in thread Unpack and Print NEW by jlope043

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.