Re: Any chance of multi-dimensional arrays?

2012-11-25 Thread Dennis Williamson
On Nov 25, 2012 1:37 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'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  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.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.