Re: [newbie] chomp acting weird (or me not understanding how it works??)
From: A. Sinan Unur (1usa_at_llenroc.ude.invalid)
Date: 01/16/05
- Next message: jim simpson: "Closing Excel"
- Previous message: Martin Kissner: "Re: Loop through a text file line by line"
- In reply to: Hendrik Maryns: "[newbie] chomp acting weird (or me not understanding how it works??)"
- Next in thread: Hendrik Maryns: "Re: [newbie] chomp acting weird (or me not understanding how it works??)"
- Reply: Hendrik Maryns: "Re: [newbie] chomp acting weird (or me not understanding how it works??)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 16 Jan 2005 17:34:10 GMT
Hendrik Maryns <hendrik_maryns@despammed.com> wrote in
news:T7ednZHf0q5HFnfcRVnyug@scarlet.biz:
> Hi,
>
> I'm reading lines from an inputfile which contains on every line a
> word, a description of it, and the word again. I want to reconstruct
> the sentence these words formed.
Since I do not speak the language in which these words are supposed to
form a sentence, I cannot figure out what your program is supposed to
do.
> "LET" is the sign for punctuation, thus means the end of the sentence
> is reached. Whend i use chomp like this:
use strict;
use warnings;
> #add this when testing
> open(INFILE, "test.txt");
You should always, with no exceptions, check if open succeeded.
> do{
> my @zinwoorden;
> chomp($lijn=<INFILE>);
The canonical way to read a file line by line until the end is to use:
while(my $lijn = <INFILE>) {
chomp $lijn;
}
> while ($lijn!~/LET/){
What do you think this does? Why are you not using an if statement here?
The rest snipped.
Please read the posting guidelines and post codes others can run by
copying and pasting in an editor. The guidelines explain how to do that.
#! /usr/bin/perl
use strict;
use warnings;
my @words;
while(<DATA>) {
chomp;
next unless $_;
last if 0 <= index $_, 'LET';
if( /^(\w+)\s+/ ) {
push @words, $1;
}
}
print "@words.\n";
__DATA__
dames N(soort,mv,basis) dame
en VG(neven) en
heren N(soort,mv,basis) heer
meneer N(soort,ev,basis,zijd,stan) meneer
de LID(bep,stan,rest) de
rector N(soort,ev,basis,zijd,stan) rector
een LID(onbep,stan,agr) een
hele ADJ(prenom,basis,met-e,stan) heel
mooie ADJ(prenom,basis,met-e,stan) mooi
avond N(soort,ev,basis,zijd,stan) avond
en VG(neven) en
een LID(onbep,stan,agr) een
hartelijk ADJ(vrij,basis,zonder) hartelijk
welkom N(soort,ev,basis,onz,stan) welkom
aan VZ(init) aan
alle VNW(onbep,det,stan,prenom,met-e,agr) al
aanwezigen ADJ(nom,basis,met-e,mv-n) aanwezig
in VZ(init) in
de LID(bep,stan,rest) de
zaal N(soort,ev,basis,zijd,stan) zaal
. LET() .
- Next message: jim simpson: "Closing Excel"
- Previous message: Martin Kissner: "Re: Loop through a text file line by line"
- In reply to: Hendrik Maryns: "[newbie] chomp acting weird (or me not understanding how it works??)"
- Next in thread: Hendrik Maryns: "Re: [newbie] chomp acting weird (or me not understanding how it works??)"
- Reply: Hendrik Maryns: "Re: [newbie] chomp acting weird (or me not understanding how it works??)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|