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
In reply to arrays of arrays by monkantar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |