Hello,
I'd like to know why the following works but with
a slight problem: this module hangs, I do not get
back to the GTM> prompt. I guess it's because I
use twice a call to $ZEOF (explanation: every line
of my 'liste.txt' file is itself the name of a file
that I also want to open to read it sequentially):
defil
set liste="liste.txt"
;ZSY "ls dirOfFiles >&"_liste
o liste
f d q:eof
. u liste r title set eof=$zeof
. u $p:(nowrap) w """"_title_"""",!
. set article=title
. o article
. f d q:eof2
. . u article r htmlLine set eof2=$zeof
. . u $p:(nowrap) w "eof-"_eof_", eof2-"_eof2,!
;. . u $p:(nowrap) w htmlLine,!
. c article
In the case where eof is true (1), your code continues to the second loop with (title,article)=""
Rather than quitting if eof is true, you "open article" which in this case is: open ""
I'm not familiar enough with GTM to know if this is where it hangs (opening a null device), but if it doesn't hNG THERE then the next lines would -- the code would be reading from the null device which likely would not terminate the read.
You need to put q:eof after the set eof=$zeof
Ben
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
the line
;. . u $p:(nowrap) w htmlLine,!
is the end all your do-loops and in consequence the line
. c article
will never be executed, so the file will not be closed.
If you want to comment out some program code in a dotted section, you should do it like this (example):
. . ; bla bla bla bla bla
Regards
Martin
Besides that: is yout cr problem solved?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok I guess you spotted where my error comes from. Could you
please tell me how to modify my code ?, if I remove "q:eof"
and add a line ". if eof quit" after "set eof=$zeof" I get
%GTM-E-IOEOF, Attempt to read past an end-of-file
At M source location defil+10^a2
%GTM-W-NOTPRINCIO, Output currently directed to device liste.txt
and I can't understande why ! (I admit i have strong difficulties
to acquaint myself with Mumps' syntactic peculiarities...)
Thanks.
Seb
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A classic problem of USEing another device, but not USEing the principal device ($P) before writing.
You have >> w "do I get here ?",! << -- where will that output go? The way it is written it will be directed to the device you were reading the file names from (liste.txt)
Like all the other lines with output you intend on reading, precede it with U $P.
(I've done this many times myself -- keeping track of what the "current device" is can save you lots of headaches)
Ben
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
o liste
f u liste q:eof d
.r title
.u $p:(nowrap) w """"_title_"""",!
.o title
.f u title q:$zeof d
..r htmlLine
..u $p:(nowrap) w htmlLine,!
.c title
c liste
u $p
w "I get Here!",!
Greets
Jens
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
o liste
f u liste q:$zeof d
. r title
. u $p:(nowrap) w "title: """_title_"""",!
. o title
. f u title q:$zeof d
. . r htmlLine
. . u $p:(nowrap) w htmlLine,!
. c title
C liste
u $p:(nowrap)
w "j'arrive ici ?",!
displays:
title: "fic hier1.txt"
f1 ligne 1
f1 ligne 2
f1 ligne 3
f1 ligne 4
f1 ligne 5
f1 ligne 6
title: "fich ier2.txt"
f2 ligne 21
f2 ligne 22
f2 ligne 23
f2 ligne 24
f2 ligne 25
f2 ligne 26
f2 c'est la fin
title: ""
<= it hangs here
Guess it hangs because of the line
. f u title q:$zeof d
when 'title' is null => the 'read' blocks.
How about adding a condition to the first 'quit:$zeof' ?
Thanks...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
n title
s title="xx"
o liste
f u liste q:($zeof!title="") d
. r title
. u $p:(nowrap) w "title: """_title_"""",!
. o title
. f u title q:$zeof d
. . r htmlLine
. . u $p:(nowrap) w htmlLine,!
. c title
C liste
u $p:(nowrap)
w "j'arrive ici ?",!
whereas this works as expected:
defil
set liste="liste.txt"
n title
s title="xx"
o liste
f u liste q:$zeof d
. r title
. i title="" q ; <= the IF is here
. u $p:(nowrap) w "title: """_title_"""",!
. o title
. f u title q:$zeof d
. . r htmlLine
. . u $p:(nowrap) w htmlLine,!
. c title
C liste
u $p:(nowrap)
w "j'arrive ici ?",!
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
there is a mistake in this line:
f u liste q:($zeof!title="") d
M(umps) interprets all expressions from right to left.
Therefore you should change the code in the following way:
f u liste q:($zeof!(title="")) d
tip:
It is sufficient to set nowrap in U $P:(NOWRAP) the first time you write something to terminal. After that you can always use the expression U $P
Regards
Martin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
your code is hanging because
. r title
will probably result in an empty string at the end of a file,
so the line
. i title="" q
is essential. Put in in your code.
Martin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I'd like to know why the following works but with
a slight problem: this module hangs, I do not get
back to the GTM> prompt. I guess it's because I
use twice a call to $ZEOF (explanation: every line
of my 'liste.txt' file is itself the name of a file
that I also want to open to read it sequentially):
defil
set liste="liste.txt"
;ZSY "ls dirOfFiles >&"_liste
o liste
f d q:eof
. u liste r title set eof=$zeof
. u $p:(nowrap) w """"_title_"""",!
. set article=title
. o article
. f d q:eof2
. . u article r htmlLine set eof2=$zeof
. . u $p:(nowrap) w "eof-"_eof_", eof2-"_eof2,!
;. . u $p:(nowrap) w htmlLine,!
. c article
w "do I get here ?",!
c liste
the output is as follows:
title: "leMonde/fichier1.txt"
eof-0, eof2-0
eof-0, eof2-0
eof-0, eof2-0
eof-0, eof2-0
eof-0, eof2-0
eof-0, eof2-0
eof-0, eof2-1
title: "leMonde/fichier2.txt"
eof-0, eof2-0
eof-0, eof2-0
eof-0, eof2-0
eof-0, eof2-0
eof-0, eof2-0
eof-0, eof2-0
eof-0, eof2-0
eof-0, eof2-1
title: ""
Is there a way to tell Mumps to get out of the first loop ?
Thanks a lot...
Sébastien
In the case where eof is true (1), your code continues to the second loop with (title,article)=""
Rather than quitting if eof is true, you "open article" which in this case is: open ""
I'm not familiar enough with GTM to know if this is where it hangs (opening a null device), but if it doesn't hNG THERE then the next lines would -- the code would be reading from the null device which likely would not terminate the read.
You need to put q:eof after the set eof=$zeof
Ben
Hello Sebastien,
caution with ; in dot-subsections!
the line
;. . u $p:(nowrap) w htmlLine,!
is the end all your do-loops and in consequence the line
. c article
will never be executed, so the file will not be closed.
If you want to comment out some program code in a dotted section, you should do it like this (example):
. . ; bla bla bla bla bla
Regards
Martin
Besides that: is yout cr problem solved?
> You need to put q:eof after the set eof=$zeof
Ok I guess you spotted where my error comes from. Could you
please tell me how to modify my code ?, if I remove "q:eof"
and add a line ". if eof quit" after "set eof=$zeof" I get
%GTM-E-IOEOF, Attempt to read past an end-of-file
At M source location defil+10^a2
%GTM-W-NOTPRINCIO, Output currently directed to device liste.txt
and I can't understande why ! (I admit i have strong difficulties
to acquaint myself with Mumps' syntactic peculiarities...)
Thanks.
Seb
A classic problem of USEing another device, but not USEing the principal device ($P) before writing.
You have >> w "do I get here ?",! << -- where will that output go? The way it is written it will be directed to the device you were reading the file names from (liste.txt)
Like all the other lines with output you intend on reading, precede it with U $P.
(I've done this many times myself -- keeping track of what the "current device" is can save you lots of headaches)
Ben
I d do it like this:
o liste
f u liste q:eof d
.r title
.u $p:(nowrap) w """"_title_"""",!
.o title
.f u title q:$zeof d
..r htmlLine
..u $p:(nowrap) w htmlLine,!
.c title
c liste
u $p
w "I get Here!",!
Greets
Jens
oops: the 2nd line has to be
f u liste q:$zeof d
The following still hangs:
defil
set liste="leMonde/liste.txt"
o liste
f u liste q:$zeof d
. r title
. u $p:(nowrap) w "title: """_title_"""",!
. o title
. f u title q:$zeof d
. . r htmlLine
. . u $p:(nowrap) w htmlLine,!
. c title
C liste
u $p:(nowrap)
w "j'arrive ici ?",!
displays:
title: "fic hier1.txt"
f1 ligne 1
f1 ligne 2
f1 ligne 3
f1 ligne 4
f1 ligne 5
f1 ligne 6
title: "fich ier2.txt"
f2 ligne 21
f2 ligne 22
f2 ligne 23
f2 ligne 24
f2 ligne 25
f2 ligne 26
f2 c'est la fin
title: ""
<= it hangs here
Guess it hangs because of the line
. f u title q:$zeof d
when 'title' is null => the 'read' blocks.
How about adding a condition to the first 'quit:$zeof' ?
Thanks...
Does someone know why the following still hangs:
defil
set liste="liste.txt"
n title
s title="xx"
o liste
f u liste q:($zeof!title="") d
. r title
. u $p:(nowrap) w "title: """_title_"""",!
. o title
. f u title q:$zeof d
. . r htmlLine
. . u $p:(nowrap) w htmlLine,!
. c title
C liste
u $p:(nowrap)
w "j'arrive ici ?",!
whereas this works as expected:
defil
set liste="liste.txt"
n title
s title="xx"
o liste
f u liste q:$zeof d
. r title
. i title="" q ; <= the IF is here
. u $p:(nowrap) w "title: """_title_"""",!
. o title
. f u title q:$zeof d
. . r htmlLine
. . u $p:(nowrap) w htmlLine,!
. c title
C liste
u $p:(nowrap)
w "j'arrive ici ?",!
Thanks.
Hello Sebastien,
there is a mistake in this line:
f u liste q:($zeof!title="") d
M(umps) interprets all expressions from right to left.
Therefore you should change the code in the following way:
f u liste q:($zeof!(title="")) d
tip:
It is sufficient to set nowrap in U $P:(NOWRAP) the first time you write something to terminal. After that you can always use the expression U $P
Regards
Martin
Nope... It's still hanging with
f u liste q:($zeof!(title="")) d
When is the condition evaluated in the FOR loop ?
Hello Sebastien,
your code is hanging because
. r title
will probably result in an empty string at the end of a file,
so the line
. i title="" q
is essential. Put in in your code.
Martin