--- Aaron Craig <[EMAIL PROTECTED]> wrote:
> At 14:44 25.06.2001 -0400, Brian Bukeavich wrote:
> >Thanks for the input.
> >My input data (which is coming out of a flat ascii file) looks similar to:
> >Jones, John 35 20 02 05/02/2001 F 060506050705040405047 11 04 01
> >Jones, John 35 20 02 05/09/2001 F 050604050705040405045 10 13 02
> >Jones, John 35 20 02 05/16/2001 F 050505040704040509048 09 01 03
> >
> >How could I "pass this function an array, or format the string for a
> >split() or something"?
>
> open (IN, "file") || die("Couldn't open file $!");
> while(<IN>)
> {
> chomp;
> my @asLines = split(/[\t\s]+/, $_);
> Load_Stat_Rec(\@asLines);
> }
> close IN;
I'd be a trifle concerned about this. First, the character class is unecessary as a
tab is
considered whitespace. However, I don't know if we have enough of the input data to
ensure that
this will work consistently. The following record would break this (because of a
middle name):
Jones, John Van 35 20 02 05/02/2001 F 060506050705040405047 11 04 01
When dealing with fixed width data, I think "unpack" would be a better choice:
my $template = 'a21a3a3a3a11a2a23a3a3a3';
while (<DATA>) {
my @rec = unpack $template, $_;
print join '|', @rec;
print "\n";
}
__DATA__
Jones, John 35 20 02 05/02/2001 F 060506050705040405047 11 04 01
Jones, John 35 20 02 05/09/2001 F 050604050705040405045 10 13 02
Jones, John 35 20 02 05/16/2001 F 050505040704040509048 09 01 03
Of course, the columns may need to be adjusted to suit the individual needs.
Cheers,
Curtis Poe
=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/