[CLUE-Tech] This should be simple...
Todd Williams
hp205ctl at hotpop.com
Thu Oct 24 23:50:28 MDT 2002
quick-n-dirty
place the following few lines of perl in a file:
#!/usr/bin/perl
while(chomp($myrecord=<>)) {
@myfields = split(/,/, $myrecord);
for $i ( 0 .. $#myfields ) {
($myfields[$i] =~ /^ +$/) && ($myfields[$i] = $oldfields[$i]);
}
print join(",", @myfields), "\n";
@oldfields = @myfields;
}
invoke like:
$ flatten.pl < raw-report.csv
David Willson wrote:
> ... but it's not. No, after almost two days of trying to RTFM, and
> side-streets galore, I just can't figure this out. And I'm not often
> getting answers here on CLUE-tech anymore, which could mean any of
> several things, but I like to think it's that I'm coming up with
> questions that can't be easily answered. Whatever... I'll get to the
> point.
>
> I need a way to loop through the lines of a file. I don't want the
> whole file in one shot, I want something like this:
>
> joe = file.open(raw-report.csv);
> myRecord = joe.readNextLine();
> myFields[] = myRecord.parseOn(",");
>
> While(!joe.EOF) {
> myRecord = joe.readNextLine();
> myFields[] = myRecord.parseOn(",");
> }
>
> Why do I want this? Because I have a file that is laid out like a tree:
> Willson, David, Lawrence
> , , Timothy
> , Katie, M.K.V.
> , Evan , Patrick
> Craft , Chris, Micheal
> And I need it to be laid out 'flat', for lack of a better word:
> Willson, David, Lawrence
> Willson, David, Timothy
> Willson, Katie, M.K.V.
> Willson, Evan , Patrick
> Craft , Chris, Micheal
>
> I need to convert all the implicit repeats into explicit/actual repeats.
>
> So, how do I? Anyone? Anyone? Bueller?
More information about the clue-tech
mailing list