In the file version the contents of the boxes are lists, even when they
have only one character. The boxes you are comparing against better
match that. try
select. c
case. , L:0 'N';'A';'Q';'GS';'G';'GM';'S';'Qsc';'AUS' do.
Henry Rich
On 3/28/2012 5:44 PM, PackRat wrote:
> I am trying to compare values in a column of CSV data loaded from a
> file against a set of selected values in order to choose records with
> matching values to be set aside for writing into another file. Easy
> task, I thought.
>
> However, the first problem I ran into was that there must be things
> about the "select" control structure that are not described anywhere,
> because, for use in matching literals, it would not work, no matter
> what I tried. So I decided to use the "if" control structure as a
> substitute for the "select" control structure. And that's when I found
> that literal comparison expressions didn't necessarily work the way I
> intuitively thought.
>
> That second problem was that I forgot that one cannot use "=" as a
> Boolean comparison verb for literals (except for single characters).
> So I had to look up Dan Bron's and Roger Hui's comparison verbs for any
> kind of matching. For "=", I used Roger's verb:
>
> eq=: -:!.0
>
> However, that's when I discovered my third problem: I could get my
> series of "if" comparisons to work perfectly for data I created
> manually, but they would NOT work correctly for data in a loaded file
> which LOOKS identical.
>
> Here are two examples, the first with data from a loaded file, the
> second with data I created to look just like the loaded data (sorry
> about the possibly crazy-looking wraparounds in email):
>
> ####################################################################
> a=. readcsv (root,datafile1)
> h=. 32
> h{a
> +----+-+-----------------------------+---+-+++---+----------+----+-+----
> -----------------------------------------------------------------------
> +
> |SMLC|G|012 Smile.Communications
> Ltd.|tlw|x|||ISR|10/31/2007|1040|S|Provides various telecomm broadband,
> roaming and traditional voice services|
> +----+-+-----------------------------+---+-+++---+----------+----+-+----
> -----------------------------------------------------------------------
> +
> datatype h{a
> boxed
>
> ]b=. ((0 1 2){h{a),'0';((8 9){h{a)
> +----+-+-----------------------------+-+----------+----+
> |SMLC|G|012 Smile.Communications Ltd.|0|10/31/2007|1040|
> +----+-+-----------------------------+-+----------+----+
> datatype b
> boxed
>
> ]c=.> 1{b
> G
> datatype c
> literal
>
> ('G' eq c)
> 0
> ####################################################################
> ]b3=. 'SMLC';'G';'012 Smile.Communications
> Ltd.';'0';'10/31/2007';'1040'
> +----+-+-----------------------------+-+----------+----+
> |SMLC|G|012 Smile.Communications Ltd.|0|10/31/2007|1040|
> +----+-+-----------------------------+-+----------+----+
> datatype b3
> boxed
>
> ]c3=.> 1{b3
> G
> datatype c3
> literal
>
> ('G' eq c3)
> 1
> ####################################################################
>
> As you can see, the type of expression ('G' eq c) that I use in my
> series of "if" comparisons worked correctly when I manually created the
> original row containing boxed data (second example above). However, as
> you can also see, that same expression did NOT work correctly in the
> first example, where the original row containing boxed data came from a
> loaded file.
>
> My questions: Why does this happen? How do I need to code things so
> that the data comparisons work correctly?
>
> The above was working with the "if" control structure, which created a
> lengthy list of comparisons with identical "do" actions. How do I have
> to code the "select" structure to make it work correctly, as above? I
> was trying to do something like the following:
>
> select. c
> case. 'N';'A';'Q';'GS';'G';'GM';'S';'Qsc';'AUS' do.
> found=. found , b
> end.
>
> As I said, I thought this short, little project was going to be easy,
> but there
> must be something about J's loaded files that I don't understand at
> all. Help
> and explanations would be greatly appreciated! Thanks in advance!
>
>
> Harvey
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm