Thanks, JohnGG. Your suggestions made a huge improvement to the script. Moreover, you showed me several better techniques I can utilize. When I first started writing it, I knew it could be way better; hence the posting. I think I am going to take a breather now and work on generating the file to excel. Since you skipped the set of rows, I can leave out $rcount. Below is how it looks now.
Thanks, Dave
use strict;
use warnings;
use Win32::OLE;
my $ex = Win32::OLE->new('Excel.Application') or die "oops\n";
my $book = $ex->Workbooks->Add;
my $sheet = $book->Worksheets(1);
my $inputFile = q{c:/INPUT.TXT};
open my $inputFH, q{<}, $inputFile or die qq{open: < $inputFile: $!\n}
+;
my $outputFile = q{C:/OUTPUT.TXT};
open my $outputFH, q{>}, $outputFile or die qq{open: > $outputFile: $!
+\n};
{
local $/ = \1173;
my $discard = <$inputFH> for 1 .. 7;
while (<$inputFH>) {
$rcount ++;
$sheet->Range("A1:CD100")->{value} = unpack("A34 A30 A40 A40
+A40 A40 A40 A2 A9 A9 A6 A40 A34 A3 A8 A1
A1 A10 A20 A10 A34 A15 A15 A15 A8 A8 A8 A8 A3 A3 A
+40 A10 A7
A20 A7 A15 A5 A8 A20 A15 A15 A15 A15 A15 A15 A1 A4
+0
A5 A8 A1 A3 A3 A3 A20 A10 A1 A15 A15 AA50 A1 A8 A1
+0
A1 A7 A3 A7 A1 A1 A15 A8 A15 A3 A15 A8 A20 A6 A6 A
+20 A15
A15 A15 A40 A15", $_);
}
}
close $inputFH;
close $outputFH;
$book->SaveAs('C:\test.xls');
undef $book;
undef $ex;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.