[Date Prev][Date Next][Subject Prev][Subject Next][
Date Index][
Subject Index]
Re: Carl's notes
- Subject: Re: Carl's notes
- From: Carl Distefano cld@xxxxxxxx
- Date: Sat, 30 Aug 2008 14:41:34 -0400
Reply to note from Harry Binswanger Sat, 30 Aug
2008 12:03:55 -0400
Harry:
> I'm working on some items in a comma-separated database, and
> it's given me occasion to use the VA@ feature for extracting a
> substring.
> ...
> It's much easier to do > than to search for the
> third comma in a line, or parse it. And much cleaner.
A cautionary note: (where "nn" is a Save/Get
identifier, and x the data-segment number) -- the feature you're
finding so handy (and it certainly is... handy) -- is a subset of
, which was also introduced in Xy4. returns *the
first 77 bytes* of Save/Get nn, whether or not S/G nn is
initialized. (If S/G nn is not initialized, returns a zero-
byte string.) This provides a pithy and memory-efficient way to
query the contents of a S/G (more precisely, the first 77 bytes
thereof) without first testing whether the S/G is initialized; it
avoids the cumbersome SUbroutine-crash test for initialization that
was necessary in Xy3. (If all you want to do is test whether a S/G
is initialized, without querying its contents, use
{less_than}0>...; S/G nn is unitialized if
equals -1.)
The nugget to take away here is that VA@nn canNOT read past the 77th
byte of S/G nn -- and, it follows, neither can . If your
target segment lies past the 77th byte, you're out of luck with VA@.
You have to switch to an iterative XS parsing procedure, like this:
XPLeNCODE v2.0
b-gin [UNTITLED]
{<}SV01,segment1,segment2,segment3,segment4,segment5,segment6
,segment7,segment8,segment9,segment10,segment11,segment12,seg
ment13,segment14,segment15,segment16,segment17,segment18,segm
ent19,segment20,segment21,segment22,segment23,segment24,segme
nt25,segment26,segment27,segment28,segment29,segment30,segmen
t31,segment32,segment33,segment34,segment35,segment36,segment
37,segment38,segment39,segment40,segment41,segment42,segment4
3,segment44,segment45,segment46,segment47,segment48,segment49
,segment50,{>};*; Data[cr|lf];*;[cr|lf]{<}SV02,,{>};*; Separa
tor = "," (e.g.)[cr|lf]{<}SV03,43{>};*; Desired segment = 43{032}
(e.g.)[cr|lf]{<}SV04,{>};*; Contents of desired segment (on E
Xit)[cr|lf]{<}SV05,{>};*; XS parse placeholder for right-side
string[cr|lf]{<}SX06,{<}IS01{>}{>};*; Working copy of data S
/G 01[cr|lf];*;[cr|lf]{<}CUa,03{>}{<}XS06,02,04,,05{>}{<}SX06
,{<}IS05{>}{>}{<}LBa{>};*; Do it (parse 43 times)[cr|lf];*;[c
r|lf]{<}PR@04{>}{<}EX{>};*; Prove it[cr|lf]
-nd
XPLeNCODE
XS parsing is fast but has the potential to cause out-of-memory
errors and destabilize XyWrite when S/G 01 (the data set) is
relatively large (depending on available memory, you might encounter
problems if S/G 01 is larger than, say, 3-4Kb. In that event, there
are alternatives).
So, yes, is "much easier", but be aware of its
limitations.
--
Carl Distefano
cld@xxxxxxxx