Re: Any chance of multi-dimensional arrays?

2012-11-26 Thread Aharon Robbins
In article mailman.13825.1353909089.855.bug-b...@gnu.org,
Eduardo Bustamante  dual...@gmail.com wrote:
There are a lot of general purpose languages (not shell languages), that
support multi-dimensional arrays. And these languages can call external
tools just fine. Python, Perl, Ruby, ... pick one. Even Awk has faked
support for multi-dimensional arrays.

Off topic, but current GNU Awk has true multidimensional arrays.

Arnold
-- 
Aharon (Arnold) Robbins arnold AT skeeve DOT com
P.O. Box 354Home Phone: +972  8 979-0381
Nof Ayalon  Cell Phone: +972 50 729-7545
D.N. Shimshon 99785 ISRAEL


Re: Any chance of multi-dimensional arrays?

2012-11-26 Thread Greg Wooledge
On Sun, Nov 25, 2012 at 06:33:19AM +0100, Rene Herman wrote:
 I'm currently writing a larger bash script to manage my (ogg vorbis) 
 music collection, including maintaining tags. Vorbis files can and 
 (mine) often will contain repeated tags such as, say, artist=David 
 Crosby and artist=Graham Nash and so on and as such, my artist 
 variable is an array.

Sounds like what you actually want is an associative array of lists,
which is not something bash provides.  You can mimic it using associative
arrays with specially mangled keys (bash 4.0 and up), but it is not a
native feature of the language.



Re: Any chance of multi-dimensional arrays?

2012-11-26 Thread Chet Ramey
On 11/25/12 12:33 AM, Rene Herman wrote:
 Good day.
 
 I know that bash arrays are 1 dimensional -- but are there any plans for
 providing multi-dimensional arrays?

I don't have any current plans to do so.  I would take a look at any
contributed code to add them, though.

Chet


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: Any chance of multi-dimensional arrays?

2012-11-26 Thread Rene Herman

On 11/26/2012 11:27 PM, Chet Ramey wrote:


I know that bash arrays are 1 dimensional -- but are there any
plans for providing multi-dimensional arrays?


I don't have any current plans to do so.  I would take a look at any
contributed code to add them, though.


Thanks for the reply. It's fairly unlikely that I will myself be able to 
try (on a sensible timescale) but it's good to know they're not vetoed.


Not being hugely experienced in bash, I was sort of impressed with there 
seemingly not being any good point in NOT using it for my collection 
management stuff -- except maybe those multi-dimensional arrays. Thought 
I'd go see what their status was...


Rene



Re: Any chance of multi-dimensional arrays?

2012-11-25 Thread Dennis Williamson
On Nov 25, 2012 1:37 AM, Rene Herman rene.her...@gmail.com wrote:

 Good day.

 I know that bash arrays are 1 dimensional -- but are there any plans for
providing multi-dimensional arrays?

 I'm currently writing a larger bash script to manage my (ogg vorbis)
music collection, including maintaining tags. Vorbis files can and (mine)
often will contain repeated tags such as, say, artist=David Crosby and
artist=Graham Nash and so on and as such, my artist variable is an
array.

 However, the same things holds for any tag and I'm currently managing
separate title, artist, genre, date, album, tracknumber, disc and
discnumber arrays with fairly ugly manual loops, whereas I would much
prefer to call them tag[i] instead and loop over them with actual for
loops. Given that tag[i] is itself an array, I can't do that though.

 When you google for this issue, you find various contrived emulations of
multi-dimensional arrays through function-accessors and such, but that's
not really what I want to do. Thought I'd see if a suggestion that
multi-dimensional arrays would really be much welcome would be welcome
here...

 The things I'm trying to do with this script seem to most naturally
belong to the realm of scripts and as such, I'm reluctant to switch to a
different language. And, in fact, I'm sort of satisfied how this is now
working. It's just that the code would much improve from multi-dimensional
array support.

 Kind regards,
 Rene


Why don't you write it in Python? It will be much easier. You can use
advanced data structures and can even store your data in a database such as
MySQL. Execution will be much faster, too.


Re: Any chance of multi-dimensional arrays?

2012-11-25 Thread Rene Herman

On 11/25/2012 03:19 PM, Dennis Williamson wrote:


Why don't you write it in Python? It will be much easier. You can
use advanced data structures and can even store your data in a
database such as MySQL. Execution will be much faster, too.


It won't be. Firstly since I'm not all that familiar with Python, but 
more importantly since I want to use the command line tools that I've 
grown accustomed to for manipulating my fairly large music database 
(oggenc, oggdec, vorbiscomment, ...). While it's certainly possible to 
launch those from any language, shell is the easy choice. Otherwise I'm 
just reading and manipulating text files, which bash is good enough at.


I moreover have no need for databases other than the file system and my 
music player's database -- and given that execution will be completely 
I/O-bound, even using pure assembly would not in fact be any faster.


All I want additionally is multi-dimensional arrays...

Kind regards,
Rene




Re: Any chance of multi-dimensional arrays?

2012-11-25 Thread Bob Proulx
Rene Herman wrote:
 All I want additionally is multi-dimensional arrays...

There are various naming conventions and schemes to simulate
multi-dimensional arrays using single dimension arrays.  Since you
want to continue with the shell and the shell has not (yet) provided
multi-dimensional arrays then the only option for you is to simulate
them.  That isn't too difficult and if you search the web there are
many different implementations with the biggest difference being
whether ordering matters or not.

Bob



Re: Any chance of multi-dimensional arrays?

2012-11-25 Thread Steven W. Orr

On 11/25/12 14:54, quoth Bob Proulx:

Rene Herman wrote:

All I want additionally is multi-dimensional arrays...


There are various naming conventions and schemes to simulate
multi-dimensional arrays using single dimension arrays.  Since you
want to continue with the shell and the shell has not (yet) provided
multi-dimensional arrays then the only option for you is to simulate
them.  That isn't too difficult and if you search the web there are
many different implementations with the biggest difference being
whether ordering matters or not.

Bob



Good answer. One suggestion that is used in awk is to use the associative 
array functionality by making an index that is a list of integers that are 
separated by commas. Here's a quick example off the top of my shiny head:


declare -A mdlist   # Multi Dimensional list

i1=44
i2=22
mdlist[$i1,$i2]=Hello

--
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net





Re: Any chance of multi-dimensional arrays?

2012-11-25 Thread Rene Herman

On 11/25/2012 08:54 PM, Bob Proulx wrote:


There are various naming conventions and schemes to simulate
multi-dimensional arrays using single dimension arrays.  Since you
want to continue with the shell and the shell has not (yet) provided
multi-dimensional arrays then the only option for you is to simulate
them. That isn't too difficult and if you search the web there are
many different implementations with the biggest difference being
whether ordering matters or not.


Yes. However, that was not my question, as was also the case for the 
previous reply. I already indicated in the original posting that I'm 
aware of work-arounds. Here it is again:


http://lists.gnu.org/archive/html/bug-bash/2012-11/msg00048.html

The question, to the bash developers (-- !) is simply if there are any 
plans for implementing multi-dimensional array support, with the two 
implied statements being that a) I'd like that and b) I have a fairly 
non-contrived use-case for them, which I thought might be welcome as an 
argument.


It's been a long time since I participated on open-source mailing-lists 
and I'm remembering why. Please don't take it the wrong way, but please, 
pretty please, unless you can answer the question, just don't bother 
replying.


Rene.



Re: Any chance of multi-dimensional arrays?

2012-11-25 Thread Eduardo Bustamante
Hey, calm down. People are just trying to help.

Also, this question has already been asked previously. Please read this:

http://lists.gnu.org/archive/html/bug-bash/2011-09/msg00062.html

(To put you in context, Chet Ramey is the current maintainer of bash).

It's not really an important feature. Bash is already doing too much for a
*shell* language (yes, note that a shell language isn't the same as a
scripting language).

There are a lot of general purpose languages (not shell languages), that
support multi-dimensional arrays. And these languages can call external
tools just fine. Python, Perl, Ruby, ... pick one. Even Awk has faked
support for multi-dimensional arrays.

Don't take me wrong though. Bash is really good, for what it was meant. If
you need complex data structures, or complex text processing, bash isn't
really the best tool for the job.

Just do yourself a favor, and start learning a new language. One that
supports custom data structures. That already has support for
multi-dimensional arrays.


P.S.: If you still have problems understanding the difference between a
shell, and a general purpose language:
http://en.wikipedia.org/wiki/Shell_(computing)#Text_.28CLI.29_shells

--
Eduardo Bustamante





On Sun, Nov 25, 2012 at 9:32 PM, Rene Herman rene.her...@gmail.com wrote:

 On 11/25/2012 08:54 PM, Bob Proulx wrote:

  There are various naming conventions and schemes to simulate
 multi-dimensional arrays using single dimension arrays.  Since you
 want to continue with the shell and the shell has not (yet) provided
 multi-dimensional arrays then the only option for you is to simulate
 them. That isn't too difficult and if you search the web there are
 many different implementations with the biggest difference being
 whether ordering matters or not.


 Yes. However, that was not my question, as was also the case for the
 previous reply. I already indicated in the original posting that I'm aware
 of work-arounds. Here it is again:

 http://lists.gnu.org/archive/**html/bug-bash/2012-11/**msg00048.htmlhttp://lists.gnu.org/archive/html/bug-bash/2012-11/msg00048.html

 The question, to the bash developers (-- !) is simply if there are any
 plans for implementing multi-dimensional array support, with the two
 implied statements being that a) I'd like that and b) I have a fairly
 non-contrived use-case for them, which I thought might be welcome as an
 argument.

 It's been a long time since I participated on open-source mailing-lists
 and I'm remembering why. Please don't take it the wrong way, but please,
 pretty please, unless you can answer the question, just don't bother
 replying.

 Rene.




Re: Any chance of multi-dimensional arrays?

2012-11-25 Thread Rene Herman

On 11/26/2012 06:51 AM, Eduardo Bustamante wrote:


Hey, calm down. People are just trying to help. Also, this question
has already been asked previously. Please read this:

http://lists.gnu.org/archive/html/bug-bash/2011-09/msg00062.html

(To put you in context, Chet Ramey is the current maintainer of
bash).


I'm quite calm, thank you :-) And thank you doubly for the link. Hadn't 
googled up much of anything concerning this myself (other than that 
multitude of existing workarounds) but Chet's reply is exactly the thing 
that I wanted -- to see if there is an interest in discussing the merits 
of implementing them, while presenting a use-case that, I feel, 
naturally belongs to the realm of scripts yet would improve nicely from 
having them.


I am not familiar with the bash source, and if they are actually hard 
and/or messy to implement, the answer might very well still be simply 
no, and I'll just continue to use the accessor-function approach that 
I'm using now -- but if it's just a matter of missing use-cases, I 
thought that me mentioning this one could be welcome while I was writing 
this script.


So. I see that that previous discussion is only from a year ago but died 
immediately again without a use-case. Chet? You probably read the list 
so pardon if you don't care for the personal CC but do you feel that this:


http://lists.gnu.org/archive/html/bug-bash/2012-11/msg00048.html

has any merit?

Kind regards,
Rene.



Any chance of multi-dimensional arrays?

2012-11-24 Thread Rene Herman

Good day.

I know that bash arrays are 1 dimensional -- but are there any plans for 
providing multi-dimensional arrays?


I'm currently writing a larger bash script to manage my (ogg vorbis) 
music collection, including maintaining tags. Vorbis files can and 
(mine) often will contain repeated tags such as, say, artist=David 
Crosby and artist=Graham Nash and so on and as such, my artist 
variable is an array.


However, the same things holds for any tag and I'm currently managing 
separate title, artist, genre, date, album, tracknumber, disc and 
discnumber arrays with fairly ugly manual loops, whereas I would much 
prefer to call them tag[i] instead and loop over them with actual for 
loops. Given that tag[i] is itself an array, I can't do that though.


When you google for this issue, you find various contrived emulations of 
multi-dimensional arrays through function-accessors and such, but that's 
not really what I want to do. Thought I'd see if a suggestion that 
multi-dimensional arrays would really be much welcome would be welcome 
here...


The things I'm trying to do with this script seem to most naturally 
belong to the realm of scripts and as such, I'm reluctant to switch to a 
different language. And, in fact, I'm sort of satisfied how this is now 
working. It's just that the code would much improve from 
multi-dimensional array support.


Kind regards,
Rene