Newbie parsing problem (cont'd)
[1/13] from: richard:coffre:francetelecom at: 29-Mar-2002 16:18
Hi,
I have a file containing data as below :
GetActiveAccounts:request = activeaccounts
GetTransactions:request = ocodereview
CancelAccount:request = cancelacc
In my code, I try to catch everything before ":request" with the following
instructions :
texte: read/lines file
foreach ligne texte
[
if parse/all ligne [ thru "request" copy nom to begin ]
[
write/append/lines output trim/head nom
]
]
But it raises the following error :
** Script Error: begin has no value
** Near: if parse/all ligne [thru "request" copy nom to begin]
Any ideas ?
and for everybody Happy Easter
Richard Coffre
France Telecom Orbiscom
T=E9l. : 01 47 61 46 28
[2/13] from: greggirwin:mindspring at: 29-Mar-2002 12:17
Hi Richard,
<< I have a file containing data as below :
GetActiveAccounts:request = activeaccounts
GetTransactions:request = ocodereview
CancelAccount:request = cancelacc
In my code, I try to catch everything before ":request"...>>
I think PARSE is one of REBOL's greatest features, but for simple splitting
there are other options as well, which are sometimes a little more
straight-forward. I don't know if this will suit your needs, but it shows
how you can use FIND and COPY/PART to do what you want. It should be easily
generalized as well.
data: [
{GetActiveAccounts:request = activeaccounts}
{GetTransactions:request = ocodereview}
{Shouldn't see this:no match here = invalid record}
{CancelAccount:request = cancelacc}
]
foreach item data [
if loc: find item ":request" [
print copy/part item subtract index? loc 1
]
]
HTH!
--Gregg
[3/13] from: al:bri:xtra at: 30-Mar-2002 7:11
Try something like:
>> texte: {GetActiveAccounts:request = activeaccounts
{ GetTransactions:request = ocodereview
{ CancelAccount:request = cancelacc
{ }
== {GetActiveAccounts:request = activeaccounts
GetTransactions:request = ocodereview
CancelAccount:request = cancelacc
}
>> output: make block! 3
== []
>> parse/all texte [any [copy nom to #":" (append output nom) thru #"^/"]
end]
== true
>> probe output
["GetActiveAccounts" "GetTransactions" "CancelAccount"]
== ["GetActiveAccounts" "GetTransactions" "CancelAccount"]
Andrew Martin
ICQ: 26227169 http://valley.150m.com/
[4/13] from: joel:neely:fedex at: 29-Mar-2002 17:04
Hi, again, Richard,
COFFRE Richard FTO wrote:
> Hi,
> I have a file containing data as below :
<<quoted lines omitted: 5>>
> instructions :
>> sample: {
{ GetActiveAccounts:request = activeaccounts
{ GetTransactions:request = ocodereview
{ CancelAccount:request = cancelacc
{
{ }
== {
GetActiveAccounts:request = activeaccounts
GetTransactions:request = ocodereview
CancelAccount:request = cancelacc
}
>> foreach line parse/all sample "^/" [
[ prefix: none parse/all line [copy prefix to ":request"]
[ if prefix [print prefix]
[ ]
GetActiveAccounts
GetTransactions
CancelAccount
-jn-
--
; Joel Neely joeldotneelyatfedexdotcom
REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip
do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] {
| e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]
[5/13] from: pyxos::netcourrier::com at: 29-Mar-2002 23:43
Thanks a lot Gregg, I'll try it on tuesday.
Happy Easter
----Message d'origine----
>De: =22Gregg Irwin=22 <greggirwin=40mindspring.com>
>A: <rebol-list=40rebol.com>
<<quoted lines omitted: 28>>
>rebol-request=40rebol.com with =22unsubscribe=22 in the
>subject, without the quotes.
-------------------------------------------------
=22Sound Mind, Sound Body=22 Juv=E9nal
=22Lire et =EAtre curieux, c'est la m=EAme chose=22 Pascal Quignard
=22Qui triomphe de lui-m=EAme poss=E8de la force=22 Lao-Tseu, extrait du Tao Te King
=22Dans la course =E0 la qualit=E9, il n'y a pas de ligne d'arriv=E9e=22 David Kearns
Allez voir mon site : http://www.desala.org
-------------------------------------------------------------
NetCourrier, votre bureau virtuel sur Internet : Mail, Agenda, Clubs, Toolbar...
Web/Wap : www.netcourrier.com
T=E9l=E9phone/Fax : 08 92 69 00 21 (0,34 =80 TTC/min)
Minitel: 3615 NETCOURRIER (0,15 =80 TTC/min)
[6/13] from: g:santilli:tiscalinet:it at: 30-Mar-2002 11:28
Hi Gregg,
On Friday, March 29, 2002, 8:17:15 PM, you wrote:
GI> print copy/part item subtract index? loc 1
or:
print copy/part item loc
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r
[7/13] from: greggirwin:mindspring at: 30-Mar-2002 11:26
Thanks Gabriele!
My first pass included the ":" after the word, as I was using index?, so I
added more code to back up a notch rather than looking for a simpler
solution.
--Gregg
[8/13] from: richard:coffre:francetelecom at: 2-Apr-2002 13:25
Thanks it works well
-----Message d'origine-----
De : Gregg Irwin [mailto:[greggirwin--mindspring--com]]
Envoy=E9 : vendredi 29 mars 2002 20:17
=C0 : [rebol-list--rebol--com]
Objet : [REBOL] Re: Newbie parsing problem (cont'd)
Hi Richard,
<< I have a file containing data as below :
GetActiveAccounts:request = activeaccounts
GetTransactions:request = ocodereview
CancelAccount:request = cancelacc
In my code, I try to catch everything before ":request"...>>
I think PARSE is one of REBOL's greatest features, but for simple splitting
there are other options as well, which are sometimes a little more
straight-forward. I don't know if this will suit your needs, but it shows
how you can use FIND and COPY/PART to do what you want. It should be easily
generalized as well.
data: [
{GetActiveAccounts:request = activeaccounts}
{GetTransactions:request = ocodereview}
{Shouldn't see this:no match here = invalid record}
{CancelAccount:request = cancelacc}
]
foreach item data [
if loc: find item ":request" [
print copy/part item subtract index? loc 1
]
]
HTH!
--Gregg
[9/13] from: richard:coffre:francetelecom at: 2-Apr-2002 13:29
I'm sorry but I don't manage to use your example.
I include it like below
texte: read/lines file
foreach line parse/all texte "^/"
[
prefix: none parse/all line [copy prefix to ":request"]
if prefix [print prefix]
]
But I have the following error :
Script: "get_request_name.r" (29-Mar-2002)
Filename? noms_requetes.txt
** Script Error: Expected one of: string! - not: block!
** Near: foreach line parse/all texte "^/"
:((
-----Message d'origine-----
De : Joel Neely [mailto:[joel--neely--fedex--com]]
Envoy=E9 : samedi 30 mars 2002 00:04
=C0 : [rebol-list--rebol--com]
Objet : [REBOL] Re: Newbie parsing problem (cont'd)
Hi, again, Richard,
COFFRE Richard FTO wrote:
> Hi,
> I have a file containing data as below :
<<quoted lines omitted: 5>>
> instructions :
>> sample: {
{ GetActiveAccounts:request = activeaccounts
{ GetTransactions:request = ocodereview
{ CancelAccount:request = cancelacc
{
{ }
== {
GetActiveAccounts:request = activeaccounts
GetTransactions:request = ocodereview
CancelAccount:request = cancelacc
}
>> foreach line parse/all sample "^/" [
[ prefix: none parse/all line [copy prefix to ":request"]
[ if prefix [print prefix]
[ ]
GetActiveAccounts
GetTransactions
CancelAccount
-jn-
--
; Joel Neely joeldotneelyatfedexdotcom
REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip
do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] {
| e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]
[10/13] from: joel:neely:fedex at: 2-Apr-2002 12:30
Hi, Richard,
COFFRE Richard FTO wrote:
> I'm sorry but I don't manage to use your example.
>
> I include it like below
>
> texte: read/lines file
>
> foreach line parse/all texte "^/"
>
There's the problem. In my simple example, the word SAMPLE
was set to a single string, and I used
parse/all sample "^/"
to break that single string into a block of "lines". In your
case, you've obtained the value of TEXTE via READ/LINES, so
it's already a block of lines.
> But I have the following error :
> Script: "get_request_name.r" (29-Mar-2002)
> Filename? noms_requetes.txt
> ** Script Error: Expected one of: string! - not: block!
> ** Near: foreach line parse/all texte "^/"
>
That error message is essentially complaining that
parse/all foo "^/"
needs for FOO to be a string, not a block. In your case
just use
foreach line texte [
etc.
-jn-
[11/13] from: richard:coffre:francetelecom at: 3-Apr-2002 8:18
Thanks a lot.
One more question not related to Rebol but I'm french and I don't know the
origin of the word foo which is often used in IT books. Could you tell me
more ?
;-)
Richard
-----Message d'origine-----
De : Joel Neely [mailto:[joel--neely--fedex--com]]
Envoy=E9 : mardi 2 avril 2002 20:31
=C0 : [rebol-list--rebol--com]
Objet : [REBOL] Re: Newbie parsing problem (cont'd)
Hi, Richard,
COFFRE Richard FTO wrote:
> I'm sorry but I don't manage to use your example.
>
> I include it like below
>
> texte: read/lines file
>
> foreach line parse/all texte "^/"
>
There's the problem. In my simple example, the word SAMPLE
was set to a single string, and I used
parse/all sample "^/"
to break that single string into a block of "lines". In your
case, you've obtained the value of TEXTE via READ/LINES, so
it's already a block of lines.
> But I have the following error :
> Script: "get_request_name.r" (29-Mar-2002)
> Filename? noms_requetes.txt
> ** Script Error: Expected one of: string! - not: block!
> ** Near: foreach line parse/all texte "^/"
>
That error message is essentially complaining that
parse/all foo "^/"
needs for FOO to be a string, not a block. In your case
just use
foreach line texte [
etc.
-jn-
[12/13] from: atruter:hih:au at: 3-Apr-2002 17:23
For exhaustive info on "foo", try
http://www.tuxedo.org/~esr/jargon/jargon.html#foo
Regards,
Ashley
[13/13] from: richard:coffre:francetelecom at: 3-Apr-2002 10:01
Thanks a lot
-----Message d'origine-----
De : [atruter--hih--com--au] [mailto:[atruter--hih--com--au]]
Envoy=E9 : mercredi 3 avril 2002 09:24
=C0 : [rebol-list--rebol--com]
Objet : [REBOL] Re: Newbie parsing problem (cont'd)
For exhaustive info on "foo", try
http://www.tuxedo.org/~esr/jargon/jargon.html#foo
Regards,
Ashley
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted