monkantar has asked for the wisdom of the Perl Monks concerning the following question:
I am a starter in PERL and new to this website. For linguistic research, I should convert textcorpora with data such as:
into:the/article book/noun he/pronoun is/verb ill/adjective
I thought writing a script for this function would be a piece of cake, but that wasn't the case...the book article noun he is ill pronoun verb adjective
I wrote a simple toy program with words and numbers to start :
the input is:
book 1 pencil 2 desk 3
the output is:
1 2 3 book pencil desk
input.txt consists of following textline:
book 1 pencil 2 desk 3
the perlscript:
This program works only for one line of text. For the moment I am reading about arrays of arrays as I want the program to work for each line in a text and push the selected items at the end of each line but I don't know if this approach will work. Does someone knows... or has written similar programs and can give me some advice for writing such a PERL script?open(MYFILE, ">output.txt") or die ("can not write to file\n"); open(INFILE, "input.txt") or die ("can not open file\n"); $w = "[a-z]"; while($line = <INFILE>) { while($line =~ /(\d+)/g) { push(@nums, $1); } while($line =~ /($w+)/g) { push(@words, $1); } } push(@nums, @words); foreach $token(@nums) { print(MYFILE "$token "); }
Thanks a lot!
Best regards
Monkantar
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: arrays of arrays
by dwm042 (Priest) on Sep 07, 2007 at 15:28 UTC | |
by jwkrahn (Abbot) on Sep 07, 2007 at 17:20 UTC | |
by monkantar (Initiate) on Sep 07, 2007 at 15:54 UTC | |
|
Re: arrays of arrays
by toolic (Bishop) on Sep 07, 2007 at 13:52 UTC | |
|
Re: arrays of arrays
by grep (Monsignor) on Sep 07, 2007 at 13:48 UTC | |
|
Re: arrays of arrays
by throop (Chaplain) on Sep 07, 2007 at 17:00 UTC | |
|
Re: arrays of arrays
by Gangabass (Vicar) on Sep 07, 2007 at 13:58 UTC |