Associative arrays are great - could we have them in PB?
For those who havent come across them:
Dim me.s(3)
me[name]="Nigel"
me[age]="36"
me[sex]="male"
STDIN is soooo powerful and it's a must-have for any Linux language, please can we have some simple means to redirect STDIN into PB, perhaps an adaption of RunProgram() that just redirects to a special global variable called STDIN$.
Ta - N
Associative Arrays & STDIN support
1. I'd love to get stdin and stdout support.
2. About the associative arrays, do you mean something like this?
2. About the associative arrays, do you mean something like this?
Code: Select all
Enumeration
#Name
#Age
#Sex
EndEnumeration
Dim You.s(2)
You(#Name) = "Nigel"
You(#Age) = "36"
You(#Sex) = "Twice a week"
Thats the way I have to do it (using constants and enumeration , but I really do mean:
Dim.me.s(3)
me("name")="Nigel"
me("age")="36"
me("sex")="not often enough
"
(dunno if this is like C or not - I know Associative Arrays from Korn Shell and Perl)
Though if it were a choice between Associatyive Arrays and STDIN support, then STDIN wins hands down. I started writing a Sys Admin tool for Linux that mimicked AIX & HPUX's Sysadmin tools. I abandoned it because there is no STDIN support
Dim.me.s(3)
me("name")="Nigel"
me("age")="36"
me("sex")="not often enough

(dunno if this is like C or not - I know Associative Arrays from Korn Shell and Perl)
Though if it were a choice between Associatyive Arrays and STDIN support, then STDIN wins hands down. I started writing a Sys Admin tool for Linux that mimicked AIX & HPUX's Sysadmin tools. I abandoned it because there is no STDIN support

Ta - N
-
- Enthusiast
- Posts: 767
- Joined: Sat Jan 24, 2004 6:56 pm
The associative arrays are often known as 'HashMap', which work as a 'key'/'value' storage, where the key can be anything unique (like an address, a string etc..). It's something i would like to implement natively in PB since a long time, but it won't probably happen with v4.0 as some other more important things are planned. Anyway, it's a good wish and it's on the todo list
.

I think you can do something like that on Windows too.dell_jockey wrote:correct me if I'm wrong, but under the Unix/Linux I/O paradigma that 'everything is a file', can't you just open STDIN, STDOUT, STDERR like you would any other file? What's missing in PB that this is not possible, perhaps just a symbolic mapping to the correct IOCTL-block?
Just wondering....
re: STDIN. Well from a Linux/Unix ksh or bash, then yes you can just redirect it the same as you would a file:
eg: cat myFile | myScript.ksh
or: ls -l | awk '/^d/ { print $NF }'
or: print "1 2 3" | awk '/^d/ { print $1, $NF }' 2>/dev/null
or: print `ls -l` | awk '/^d/ { print $1, $NF }' 2>/dev/null
or: ls -l /sdsdsd 2>/dev/null | awk '/^d/ { print $1, $NF }'
this sort of flexibility with commands, files and redirection of input and output makes Unix scripting v-e-r-y powerful and extendible. STDOUT is easy to do from within PB, but not STDIN - It would be invaluable.
eg: cat myFile | myScript.ksh
or: ls -l | awk '/^d/ { print $NF }'
or: print "1 2 3" | awk '/^d/ { print $1, $NF }' 2>/dev/null
or: print `ls -l` | awk '/^d/ { print $1, $NF }' 2>/dev/null
or: ls -l /sdsdsd 2>/dev/null | awk '/^d/ { print $1, $NF }'
this sort of flexibility with commands, files and redirection of input and output makes Unix scripting v-e-r-y powerful and extendible. STDOUT is easy to do from within PB, but not STDIN - It would be invaluable.
Ta - N
For those curious (and as a sneaky bump
http://php.net/manual/en/ref.array.php
PHP's arrays are also associative and once you start getting used to them you'll love them.
It would certainly make cross porting PB and PHP apps very easy for folks like me since I use associative arrays a lot in PHP.
Fred, I was thinking though, can't you just copy the existing PB list code and tweak it to have a hashmap? That should provide the core functionality of associate arrays and most of the existing list code could be copied and reused as well with minimal editing I hope?
I.e copy LinkedList lib into a LinkedListAssociative if you know what I mean

PHP's arrays are also associative and once you start getting used to them you'll love them.
It would certainly make cross porting PB and PHP apps very easy for folks like me since I use associative arrays a lot in PHP.
Fred, I was thinking though, can't you just copy the existing PB list code and tweak it to have a hashmap? That should provide the core functionality of associate arrays and most of the existing list code could be copied and reused as well with minimal editing I hope?
I.e copy LinkedList lib into a LinkedListAssociative if you know what I mean
