"Albert L. Lukaszewski" wrote:
> 
> At the earlier suggestion of Rob Dixon (rob[at]dixon.nildram.co.uk), I
> here present a sample of the data I am trying to convert, the output I
> desire, and the program as I have written it thus far.
> 
> I am using "4Q246.db" as a sample of the larger file.  In between each
> text, I want it to add three CRs, two blank lines, between the end of
> the one text and the title of the next.  Ultimately, I would love it
> if they could all go into files according to their names,

Where do you get their names from?

> but I am
> pressed for time and just need the second field for each line collated
> for right now.
> 
> 
> DATA:
> 
> 4Q246.1.1, yhwl[(], prep.|s5, prep.loc~,
> 4Q246.1.1, tr#, v-G11, v., <yr# to settle
> 4Q246.1.1, lpn, v-G10, v., <lpn to fall
> 4Q246.1.1, Mdq, prep., prep.locative, <Mdq before
> 4Q246.1.1, )ysrk, n-mse, p.obj., <)srk chair
> 
> 4Q246.1.2, )kl[m], n-mse, vocative, <Klm king
> 4Q246.1.2, )ml(<m>[l], prep.|n-mse, prep.temporal|p.obj., <Ml( forever
> 4Q246.1.2, ht), p2, s., <ht( you
> 4Q246.1.2, zgr, adj-msa, adj.modifier, <zgr angry/distressed
> 4Q246.1.2, Kyn#w, c.conj.|n-mpc|s2, s., <yn# year
> 
> 4Q246.1.3, ...,, ,
> 4Q246.1.3, Kwzx, n-msc|s2, , <wzx vision
> 4Q246.1.3, )lkw, c.conj.|adj-mse, adj.substantive,
> 4Q246.1.3, ht), p2, s., <ht) you
> 4Q246.1.3, d(, prep., prep.temporal, <d( until
> 4Q246.1.3, )ml(, n-mse, p.obj., <Ml( forever
> 
> OUTPUT (right justified eventually):
> 
> )ysrk Mdq lpn tr# yhwl[(]   4Q246.1.1
> Kyn#w zgr ht) )ml(<m>[l] )kl[m]   4Q246.1.2,
> )ml( d( ht) )lkw Kwzx ...   4Q246.1.3

Using your data as an example, this will do what you want:

#!/usr/bin/perl
use warnings;
use strict;

my $file = '4Q246.db';
open INFO, $file or die "Cannot open $file: $!";
open OUT, ">>qa.txt" or die "Cannot open file 'qa.txt' $!";

my %data;
while ( <INFO> ) {
    next unless /\S/;
    my ( $ref, $form ) = split /\s*,\s*/;
    if ( exists $data{ $ref } ) {
        $data{ $ref } = "$form $data{ $ref }";
        }
    else {
        while ( my ( $key, $val ) = each %data ) {
            print OUT "$val $key\n";
            delete $data{ $key };
            }
        $data{ $ref } = $form;
        }
    }
while ( my ( $key, $val ) = each %data ) {
    print OUT "$val $key\n";
    }

__END__



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to