ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Thanks! I like that "set - ${REST//:/ }" approach. I keep forgetting how powerful that is.
\b\w.*\b?!.*\b\k\b
are actually 2 regexps, but I got errors about the use of an unexpected '(' when I wrote it like this:
(\b\w.*\b)(?!.*\b\k\b)
The first is to match a word (\w) (with any character followed by whatever ;-) with a boundary (\b) so you get the 1st regexp.
The second is to mean that the word I just found should not be followed by another occurrence of itself (\k) even if there are other characters in between (.*); same boundary applies here.
In other words, I had expected to get a list of ${RECORD[#].MAINMENU} entries as if they were sorted through uniq: in a list of "apple pear egg omelet pear", I'd get "apple pear egg omelet"
Well I was not able to find anything to tell me about \k, but assuming that is ok, the reason you would get -
unexpected '(' - that I can see is because ? means 0 or 1 of the preceding character, so:
(\b\w.*\b) - alphanumeric followed by any character and between word boundaries
(? - zero or one lot of left round bracket
!.*\b\k\b) - assuming your understanding of \k - not any character followed by the same word inside a word boundary (of course this also now means the right hand round bracket is part of the regex which is also wrong)
So presumably removing the ? may alleviate the problem??
Unfortunately I have to wait till I get home to test as no access to ksh here
Unfortunately ksh is not my strength either and I am struggling to find a good tutorial (if you have one i would appreciate a link) that lists this type of thing
What I have found is that the issue is not exactly to do with your regex but where you have put it:
Code:
select choice in ${RECORD[*].MAINMENU@(\b\w.*\b!.*\b\k\b)}
# should be
select choice in ${RECORD[*].MAINMENU}@(\b\w.*\b!.*\b\k\b)
Notice the move of the curly braces.
The issue we now have is that the following construct is incorrect for displaying all in an array:
Code:
echo ${RECORD[*].MAINMENU}
This results in a weird arithmetic error.
So I guess my question to you is, do you know or have notes on the correct format to display all items for a single element?
I have not (yet), I've been putting some stuff together from fragments all over the place; That was mostly the regexp, which I took and adapted, since it was for another language. But this is something that helps me move further. Will keep you posted on some findings and solutions. I still think this is potentially a very nice way to handle data.
Well I am not sure of the OPs exact requirements, but personally I would still like the question answered on whether or not it is possible (and if so how) to display, for
example, all of the MAINMENU (associative sub index) items for all RECORDs or if only possible if you loop through?
For every problem multiple solutions exist; I could think up a quick and dirty one that would read my config file multiple times. However, I'm never fond of too much file i/o. In fact, I hate file i/o, and will try to reduce it as much as possible. So, what I thought up was this array-approach, as it is closest to how I would do things while programming (in C(++)): a struct or a class in that case.
So the question is NOT about how do I create my menu, but: how do I handle regular expressions to search and sort data in my (compound) array? (if it is at all possible).
I have not found a solution yet on how I can manipulate this compound array.
As a side note: as is often the case with me: sometimes I find "new" (for me) things that are possible. I'm one of those who lies to explore there, and see what's possible so I have more tools to work with, which often lead to being able to solve things that are otherwise much harder / next to impossible to solve.
bigears: I was working on something else and the rest was quick&dirty, as I was looking into the concepts of compound variables and how to manipulate in that. I know grail's code is much cleaner in that aspect, and for the sake of getting a great example, I've fixed the code for that :-)
I've been looking a bit about, and I think I found one of the big problems:
Code:
echo ${RECORD[*].MAINMENU}
is not valid syntax, which really is a pity. One of the solutions is to create a new variable and loop through the array... but doesn't that really defeat the purpose :-)
Thinking up other ways to work around this issue... Currently checking out http://oreilly.com/catalog/korn2/chapter/ch04.html#t3 and see how that brings us further.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.