^L
Mary Clary
345 High Road
Sometown, MA, 38776
#23 23232#
#23 23232#
08 Apr 1997 11 Mar 2002
message to include 1
message to include 2
Beginning of account detail information for a/c #23 23232#
fgbdfgehbetr 1
67jufgjtykutyruk 2
rytjrytjrtyjryt 3
fghmfhmjryyuy 4
hethe5tyhdtghetyh 5
EOE
^L
Bill V. Jones
Bill Jones
1214 Reno Heights
Burbank, CA, 43523
#444-7777#
#444-7777#
22 Nov 2002 13 Aug 2005
message line 1
message line 2
Beginning of account detail information for a/c #444-7777#
This is data line 1
and here is data line 2
and 3 here
oh, and number 4
and a speech
Now is the winter of our discontent
Made glorious summer by this sun of York;
And all the clouds that lour'd upon our house
In the deep bosom of the ocean buried.
Now are our brows bound with victorious wreaths;
Our bruised arms hung up for monuments;
Our stern alarums chang'd to merry meetings,
Our dreadful marches to delightful measures.
Grim-visag'd war hath smooth'd his wrinkled front;
And now, -- instead of mounting barbed steeds
To fright the souls of fearful adversaries, --
He capers nimbly in a lady's chamber
To the lascivious pleasing of a lute.
But I, -- that am not shap'd for sportive tricks,
Nor made to court an amorous looking-glass;
I, that am rudely stamp'd, and want love's majesty
To strut before a wanton ambling nymph;
I, that am curtail'd of this fair proportion,
Cheated of feature by dissembling nature,
Deform'd, unfinish'd, sent before my time
Into this breathing world scarce half made up,
And that so lamely and unfashionable
That dogs bark at me as I halt by them; --
Why, I, in this weak piping time of peace,
Have no delight to pass away the time,
Unless to spy my shadow in the sun,
And descant on mine own deformity:
And therefore, -- since I cannot prove a lover,
To entertain these fair well-spoken days, --
I am determined to prove a villain,
And hate the idle pleasures of these days.
Plots have I laid, inductions dangerous,
By drunken prophecies, libels, and dreams,
To set my brother Clarence and the king
In deadly hate the one against the other:
And if King Edward be as true and just
As I am subtle, false, and treacherous,
This day should Clarence closely be mew'd up, --
About a prophecy which says that G
Of Edward's heirs the murderer shall be.
Dive, thoughts, down to my soul: -- here Clarence comes.
EOE
^L
Fred Bloggs
23 Corporation St.
New York, NY, 12345
#1234567#
#1234567#
13 Mar 1998 24 Oct 2001
message line 1
message line 2
Beginning of account detail information for a/c #1234567#
This is data line 1
and here is data line 2
and 3 here
EOE
####
use strict;
use warnings;
# Initialise file names and open files, one
# for reading, two for writing.
#
my $inputFile = q{spw579580.inp};
my $headerFile = q{spw579580.hdrs};
my $detailFile = q{spw579580.dets};
open my $inputFH, q{<}, $inputFile
or die qq{open: $inputFile: $!\n};
open my $headerFH, q{>}, $headerFile
or die qq{open: $headerFile: $!\n};
open my $detailFH, q{>}, $detailFile
or die qq{open: $detailFile: $!\n};
# Set up start and end sentinels.
#
my $startSentinel = q{^L};
my $endSentinel = q{EOE};
# Compile regex to pull out records. Note the
# \Q ... \E to quote regex metacharacters if your
# record start and stop sentinels contain them.
#
my $rxExtractRecord = qr
{(?xms)
\Q$startSentinel\E\n
(.*?)
(?=\Q$endSentinel\E\n|\z)
};
# Slurp whole file into string.
#
my $completeFile;
{
local $/;
$completeFile = <$inputFH>
}
# Do a global match against compiled regex to
# pull out records and put them in an array. They
# will have the start and end record sentinels
# removed by this process.
#
my @records = $completeFile =~ m{$rxExtractRecord}g;
# Process each record in a loop.
#
foreach my $record (@records)
{
# We now have the record in a scalar
# variable $record ready for processing.
#
# FURTHER PROCESSING GOES HERE ...
}
# Close open filehandles.
#
close $inputFH
or die qq{close: $inputFile: $!\n};
close $headerFH
or die qq{close: $headerFile: $!\n};
close $detailFH
or die qq{close: $detailFile: $!\n};
####
use strict;
use warnings;
# Initialise file names and open files, one
# for reading, two for writing.
#
my $inputFile = q{spw579580.inp};
my $headerFile = q{spw579580.hdrs};
my $detailFile = q{spw579580.dets};
open my $inputFH, q{<}, $inputFile
or die qq{open: $inputFile: $!\n};
open my $headerFH, q{>}, $headerFile
or die qq{open: $headerFile: $!\n};
open my $detailFH, q{>}, $detailFile
or die qq{open: $detailFile: $!\n};
# In a code block localise $/, the input record
# separator, to your end of record string.
#
{
local $/ = qq{EOE\n};
# Read each record in a while loop. Strip the
# start and end record sentinels off.
#
while (defined(my $record = <$inputFH>))
{
$record =~ s{\A\^L\n}{};
$record =~ s{EOE\n\z}{};
# We now have the record in a scalar
# variable $record ready for processing.
#
# FURTHER PROCESSING GOES HERE ...
}
}
# Close open filehandles.
#
close $inputFH
or die qq{close: $inputFile: $!\n};
close $headerFH
or die qq{close: $headerFile: $!\n};
close $detailFH
or die qq{close: $detailFile: $!\n};
####
my $detailsLinesWritten = 0;
####
my @items = split m{\n}, $record, 17;
####
my $details = pop @items;
my $detailsLineCt = ($details =~ tr/\n//);
####
print $detailFH $details;
$detailsLinesWritten += $detailsLineCt;
####
sub stripSpaces
{
my $toStrip = shift;
return
$toStrip =~ m{\A\s*(.+?)\s*\z}
? $1
: q{};
}
####
my $fld2 = q{Some company text};
my $fld3 = q{Some other company text};
...
my $fld5 = q{};
...
my $fld14 = q{};
####
my $fld1 = q{};
my $fld6 = q{};
...
my $fld15 = q{};
####
my ($fld1, $fld6, $fld7, $fld8, $fld11, $fld12, $fld15)
= (q{}) x 7;
####
$fld1 = stripSpaces($items[6]);
####
# Pull out two dates from line 12 with a global match of
# 2 digits, a space, three letters, a space 4 digits. The
# round brackets allow you to capture what matches inside
# them.
#
my ($startPeriod, $endPeriod) =
$items[10] =~ m{(\d\d\s[A-Za-z]{3}\s\d{4})}g;
# Transform date by capturing (round brackets) the day,
# month and last 2 digits of the year in $1, $2 and $3
# then concatenating them; the 'e' flag after the
# regular expression tells the regex engine to execute
# the code to compute the substituting string. The '.'
# is the string concatenation operator.
#
($fld11 = $startPeriod)
=~ s{(\d\d)\s([A-Za-z]{3})\s\d\d(\d\d)}{$1 . $2 . $3}e;
($fld12 = $endPeriod)
=~ s{(\d\d)\s([A-Za-z]{3})\s\d\d(\d\d)}{$1 . $2 . $3}e;
####
my $line3 = stripSpaces($items[1]);
my $line4 = stripSpaces($items[2]);
if($line3)
{
$fld6 = $line3;
$fld15 = $line4;
}
else
{
$fld6 = $line4;
}
####
my $str1 = q{abc};
my $str2 = q{zyxwvut};
my $template = q{A5A5};
my $packed = pack $template, $str1, $str2;
print qq{>$packed<\n};
####
>abc zyxwv<
####
my $hdrTemplate
= q{A18}
. q{A40} x 9
. q{A7} x 2
. q{A10) x 2
. q{A40}
. q{A8}
. q{A6};
####
my $headerStr = pack $hdrTemplate
, $fld1
, $fld2
, $fld3
, $fld4
, $fld5
, $fld6
, $fld7
, $fld8
, $fld9
, $fld10
, $fld11
, $fld12
, $fld13
, $fld14
, $fld15
, $detailsLinesWritten
, $detailsLineCt;
print $headerFH qq{$headerStr\n};