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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |