Sponsored Content
Top Forums Shell Programming and Scripting accessing my first element of array Post 84951 by afadaghi on Thursday 29th of September 2005 03:51:39 PM
Old 09-29-2005
Tools accessing my first element of array

Hello everyonel,
I have an array set like so
num=4
read name
arr[$num]=name
I go through while loop to assign different values to different array element from 1 to 4. when I try to access the FIRST element of the array I get the last one first. Like if I say ${arr[1]} it will show the last element of the array that I populated last. I do not know how to reset the pointer so when I say ${arr[1]} it will show me the very first element.


Appreciate your help.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl delete an element from array

Probably I am not seeing it or I am not using the "delete" correctly I had the following codes but it does not work for me #!/bin/perl -w ... @sysFile1 = (a_b, a_c, a_d); @sysFile2 = (a_c, a_e, b_f); foreach $line1 (@sysFile1){ trim(\$line1); (my $tmp1, my $tmp2) = split/_/,... (6 Replies)
Discussion started by: ahtat99
6 Replies

2. Programming

Structure element accessing issue...

Hi all, Can someone advice, why I'm getting a segmentation fault on a Linux system for a program which looks like the below one--: typedef struct idev{ int p, char q; } Idev; typedef struct abc{ int i; Idev *idev_ptr; } ABC; int main(){ ABC a_var; char str; int... (4 Replies)
Discussion started by: Praveen_218
4 Replies

3. Shell Programming and Scripting

Shift array element

I want to delete and 0th element of array in shell scrpit and also shift all others to one level up. (2 Replies)
Discussion started by: darshakraut
2 Replies

4. Programming

how to put element of an array to first position.

hi, I have a array like my $array = ( "apple","ball","cat","dog","elephant"); how to push some element in the array to the first position. for example my final array should be elephant apple ball cat dog (5 Replies)
Discussion started by: vprasads
5 Replies

5. Shell Programming and Scripting

remove an element from array

I need to remove an element from the below array variable TABLENAME. #!/bin/ksh set -A TABLENAME "mirf roxar keke mirs" echo "the array is ${TABLENAME}" If i need to remove say keke and have the final TABLENAME as below, how this could be achieved. Pls throw some light. echo "Modified... (3 Replies)
Discussion started by: michaelrozar17
3 Replies

6. Shell Programming and Scripting

Multiplying array element

I am trying to take all the elements of an array and multiply them by 2, and then copy them to a new array. Here is what I have i=0 for true in DMGLIST do let DMGSIZES2="${DMGSIZES}"*2 let i++ done unset i echo ${DMGSIZES2} It does the calculation correctly for the first element,... (7 Replies)
Discussion started by: nextyoyoma
7 Replies

7. Shell Programming and Scripting

Filter output as an array element

I am filtering the value of Server status from a file and am storing it in a temp file which I compare later to exit with appropriate status. I am wondering if I can directly output the value of Server status as an array element and then compare the value of elements to get the right exit status ... (2 Replies)
Discussion started by: paslas
2 Replies

8. Shell Programming and Scripting

Not able to call an element from an array in ksh

Hi, I have: # Initialize variables #!/usr/bin/ksh FILENM=$1 INDEX=0 # read filename echo "You are working with the Config file: $FILENM" while read line do echo $line data=$line ((INDEX=INDEX+1)) done <"$FILENM" (3 Replies)
Discussion started by: Marc G
3 Replies

9. UNIX for Advanced & Expert Users

Array Element

This question is for someone that's more familiar with Array Element. I need to know if the maximum array element that can be assigned is 1024 and if its so, Is there a workaround solution when the counter exceeded 1024? param_array="$param_nam" counter=$counter+1 #to avoid space... (3 Replies)
Discussion started by: cumeh1624
3 Replies

10. Shell Programming and Scripting

Awk: check element in array and it's value

Hello, I want to see if element exists in array, if so then, check it's corresponding value. Column 4 is position and column 1 is the chromosome for it. There are duplicates for one position on one chromosome. I want to check if same position exists on different chromosome: Data... (8 Replies)
Discussion started by: genome
8 Replies
ARRAY_FILTER(3) 							 1							   ARRAY_FILTER(3)

array_filter - Filters elements of an array using a callback function

SYNOPSIS
array array_filter (array $array, [callable $callback], [int $flag]) DESCRIPTION
Iterates over each value in the $array passing them to the $callback function. If the $callback function returns true, the current value from $array is returned into the result array. Array keys are preserved. PARAMETERS
o $array - The array to iterate over o $callback - The callback function to use If no $callback is supplied, all entries of $array equal to FALSE (see converting to boolean) will be removed. o $flag - Flag determining what arguments are sent to $callback: o ARRAY_FILTER_USE_KEY - pass key as the only argument to $callback instead of the value o ARRAY_FILTER_USE_BOTH - pass both value and key as arguments to $callback instead of the value RETURN VALUES
Returns the filtered array. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.6.0 | | | | | | | Added optional $flag parameter and constants | | | ARRAY_FILTER_USE_KEY and ARRAY_FILTER_USE_BOTH | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 array_filter(3) example <?php function odd($var) { // returns whether the input integer is odd return($var & 1); } function even($var) { // returns whether the input integer is even return(!($var & 1)); } $array1 = array("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5); $array2 = array(6, 7, 8, 9, 10, 11, 12); echo "Odd : "; print_r(array_filter($array1, "odd")); echo "Even: "; print_r(array_filter($array2, "even")); ?> The above example will output: Odd : Array ( [a] => 1 [c] => 3 [e] => 5 ) Even: Array ( [0] => 6 [2] => 8 [4] => 10 [6] => 12 ) Example #2 array_filter(3) without $callback <?php $entry = array( 0 => 'foo', 1 => false, 2 => -1, 3 => null, 4 => '' ); print_r(array_filter($entry)); ?> The above example will output: Array ( [0] => foo [2] => -1 ) Example #3 array_filter(3) with $flag <?php $arr = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4]; var_dump(array_filter($arr, function($k) { return $k == 'b'; }, ARRAY_FILTER_USE_KEY)); var_dump(array_filter($arr, function($v, $k) { return $k == 'b' || $v == 4; }, ARRAY_FILTER_USE_BOTH)); ?> The above example will output: array(1) { ["b"]=> int(2) } array(2) { ["b"]=> int(2) ["d"]=> int(4) } NOTES
Caution If the array is changed from the callback function (e.g. element added, deleted or unset) the behavior of this function is unde- fined. SEE ALSO
array_map(3), array_reduce(3), array_walk(3). PHP Documentation Group ARRAY_FILTER(3)
All times are GMT -4. The time now is 01:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy