For Quality purpouses, LoneWolf 's mail on Friday 06 February 2004 16:57 may
have been monitored or recorded as:
I've been working with this since wolf and jeff and john sent me some
stuff, I think I actually based everything on wolf's code excerpts. I'm
sure my final code is going to not be perfect, but at least I have the
piece of mind of knowing that I can get this thing some better then it was.
I'm still not sure on making it a sub that I can use on anything, but I'll
deal with that issue another day.
easy: (notice: thats the same script as priviously but has the parse in a
sub:)
---snip---
#!/usr/bin/perl
use strict;
use warnings;
my (@fields, $lng);
sub whatever {
if (@_) {
foreach my $infile (@_) {
my ($i,$rec);
open INFILE, $infile or die Can't open $infile: $!;
open OUTFILE, ${infile}.out or die Can't open ${infile}.out at home:
$!;
while (INFILE) {
$rec++;
chomp;
[EMAIL PROTECTED] = split /\s*\|\s*/, $_;
$fields[0] =~ s/^\s+//;
#there is probably a way to get rid of the trailing spaces in the first
entry using split,I just couldnt think of any.
$lng = @fields unless $lng; #set $lng for first record
print The following record: $i has , scalar @fields, fields as compared
to $lng fields in the first record! Skip. : $_\n and next unless $lng ==
@fields;
#poor quality control of your input data: check if all reords have the same
number of fields or skip and print record otherwise.
$i++;
print OUTFILE $i;
print OUTFILE |$_ foreach (@fields);
print OUTFILE |$fields[0]\n; #your trailing ID
}
close INFILE;
close OUTFILE;
print Read $rec records from ./sql/$infile and printed $i into ./
${infile}.out\n;
} #end foreach
return 1;
}
else {return undef;}
} #end sub whatever
---snap---
call it with whatever('path/to/firstfile', 'path/to/secondfile',...)
Enjoy, Wolf
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response