Sponsored Content
Full Discussion: store key value
Top Forums Shell Programming and Scripting store key value Post 302217733 by BMDan on Wednesday 23rd of July 2008 11:52:53 AM
Old 07-23-2008
In PHP? No problem.
In Perl? Yep, we call those Hashes.
In very nearly any other language? Sure, with varying levels of straightforwardness.
In Bash? Not without some seriously-absurd buffoonery. It's almost always better to find another way to do it. Is this absolutely what you need, and no other approach will work?

Something like:
Code:
key="some_key" array[$(i=0; while [ x${arrayname[$i]} != x ]; do if [ x${arrayname[$i]} == x$key ]; then break; fi; export i=$(($i+1)); done; arrayname[$i]=$key; echo $i)]="value"

should work, but I kept running into scope issues with $arrayname. So:
Code:
key="some_key"; array[$(i=0; while [ x${arrayname[$i]} != x ]; do if [ x${arrayname[$i]} == x$key ]; then break; fi; export i=$(($i+1)); done; echo $i)]="value"
if [ x${arrayname[$i]} == x ]; then arrayname[$i]=$key; fi

Now, to retrieve, something like:
Code:
i=0; while [ x${arrayname[$i]} != x ]; do echo '$array['${arrayname[$i]}']="'${array[$i]}'"'; i=$(($i+1)); done

will retrieve all values, while
Code:
key="some_key"; i=0; while [ x${arrayname[$i]} != x ]; do if [ x${arrayname[$i]} == x$key ]; then echo ${array[$i]}; fi; i=$(($i+1)); done

will retrieve some_key.

Quite likely to break, full of holes, contains at least one bug, and generally inadvisable to use. Enjoy!

Last edited by BMDan; 07-23-2008 at 02:57 PM..
 

6 More Discussions You Might Find Interesting

1. Programming

how can i store it ?

how can i store a value which is larger than a long double value?? please help me.. -sham- (2 Replies)
Discussion started by: shamal
2 Replies

2. Shell Programming and Scripting

grep and store

When i grep a file and store it in a file it is storing as a zero byte file any way to avoid that..... (6 Replies)
Discussion started by: arunkumar_mca
6 Replies

3. Cybersecurity

SSH key code versus server key code

Hi, When logging in using SSH access (to a remotely hosted account), I received a prompt to accept a server's key fingerprint. Wrote that string of code down for comparision. Already emailed my host for their listing of the string of code for the server's key fingerprint (for comparison,... (1 Reply)
Discussion started by: Texan
1 Replies

4. UNIX for Dummies Questions & Answers

Pressing backspace key simulates enter key

Hi, Whenever i press the backspace key, a new line appears, i.e. it works like a enter key. :confused: Thanks (2 Replies)
Discussion started by: vibhor_agarwali
2 Replies

5. Solaris

Solaris 8 ssh public key authentication issue - Server refused our key

Hi, I've used the following way to set ssh public key authentication and it is working fine on Solaris 10, RedHat Linux and SuSE Linux servers without any problem. But I got error 'Server refused our key' on Solaris 8 system. Solaris 8 uses SSH2 too. Why? Please help. Thanks. ... (1 Reply)
Discussion started by: aixlover
1 Replies

6. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies
APC_DEFINE_CONSTANTS(3) 						 1						   APC_DEFINE_CONSTANTS(3)

apc_define_constants - Defines a set of constants for retrieval and mass-definition

SYNOPSIS
bool apc_define_constants (string $key, array $constants, [bool $case_sensitive = true]) DESCRIPTION
define(3) is notoriously slow. Since the main benefit of APC is to increase the performance of scripts/applications, this mechanism is pro- vided to streamline the process of mass constant definition. However, this function does not perform as well as anticipated. For a better-performing solution, try the hidef extension from PECL. Note To remove a set of stored constants (without clearing the entire cache), an empty array may be passed as the $constants parameter, effectively clearing the stored value(s). PARAMETERS
o $key - The $key serves as the name of the constant set being stored. This $key is used to retrieve the stored constants in apc_load_constants(3). o $constants - An associative array of constant_name => value pairs. The constant_name must follow the normal constant naming rules. value must evaluate to a scalar value. o $case_sensitive - The default behaviour for constants is to be declared case-sensitive; i.e. CONSTANT and Constant represent different values. If this parameter evaluates to FALSE the constants will be declared as case-insensitive symbols. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 apc_define_constants(3) example <?php $constants = array( 'ONE' => 1, 'TWO' => 2, 'THREE' => 3, ); apc_define_constants('numbers', $constants); echo ONE, TWO, THREE; ?> The above example will output: 123 SEE ALSO
apc_load_constants(3), define(3), constant(3), Or the PHP constants reference. PHP Documentation Group APC_DEFINE_CONSTANTS(3)
All times are GMT -4. The time now is 07:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy