10-22-2008
Hi Jim,
I really appreciate your help! Two final questions:
- When you use unset, you refer to the array with "$" and "{}". When I use them I get an error:
michael-browns-powerbook-g4-15:~ msb65$ array=(1 2 3 4)
michael-browns-powerbook-g4-15:~ msb65$ unset ${array[1]}
-bash: unset: `2': not a valid identifier
The only way I get it work is if I type:
michael-browns-powerbook-g4-15:~ msb65$ unset array[1]
Why is that?. What is the difference between the two methods?
- Is there any way to just eliminate an array element (ie reorder the array)?
Mike
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi all
I have a file that i'm running and exec(cat ./dat) against..and putting its contents into any array, then doing an exploding the array into a multi-dimension array...
The 15 multi-dimensional arrays have elements that are null/empty, I would like to remove/unset these elements and then... (2 Replies)
Discussion started by: zeekblack
2 Replies
2. Shell Programming and Scripting
How can I get my array to understand the double-quotes I'm passing into it are to separate text strings and not part of an element? here's what I'm working with...
db2 -v connect to foo
db2 -x "select '\"' || stats_command || '\",' from db2law1.parallel_runstats where tabname = 'BAZ'"
set... (4 Replies)
Discussion started by: djschmitt
4 Replies
3. UNIX for Dummies Questions & Answers
Hi,
I have an array containing following sample information
@array = qw (chr02 chr02 chr02 chr02 chr02 chr03 chr03 chr04 chr04 chr05 chr05 chr05 chr07 chr07) I need to replace all duplicate entries by an underscore to get the following output@array = qw (chr02 _ _ _ _ chr03 _ chr04 _ chr05 _ _... (4 Replies)
Discussion started by: pawannoel
4 Replies
4. UNIX for Dummies Questions & Answers
Is there a way to print multiple array elements without iterating through the array using bash?
Can you do something like...
echo ${array}and get all those separate elements from the array? (2 Replies)
Discussion started by: jrymer
2 Replies
5. Shell Programming and Scripting
I have a script which takes backup of some configuration files on my server. It does that by using an array which contains the complete path to the files to backup.
It copys the files to a pre defined dir. Each "program" has it's own folder, ex. apache.conf is being copied to /predefined... (7 Replies)
Discussion started by: dnn
7 Replies
6. Programming
Hi everyone, :)
I'm trying to make a simple C program that scans an array of chars to see if its elements are similar.
I can't understand what's wrong. Could you help me to fix this? Here is the code.
Thanks!
#include<stdio.h>
int main() {
int arr;
int i, len;
int flag =... (10 Replies)
Discussion started by: IgorGest
10 Replies
7. Shell Programming and Scripting
Hi
I wanted to print random elements from an array at bash shell
I use the following code, but I always see first element getting printed
#!/bin/bash
c=1
expressions=(pink red white yellow purple)
while ]; do
echo "The value of RANDOM is $RANDOM"
selectedexpression=${expressions}]};... (5 Replies)
Discussion started by: Priya Amaresh
5 Replies
8. Shell Programming and Scripting
Hi All,
need help with reading the array and sum of the array elements.
given an array of integers of size N . You need to print the sum of the elements in the array, keeping in mind that some of those integers may be quite large.
Input Format
The first line of the input consists of an... (1 Reply)
Discussion started by: nishantrefound
1 Replies
9. UNIX for Beginners Questions & Answers
#!/bin/bash
X=(2H 4S 10D QC JD 9H 8S)
How do I unset the 10D from this array and save it to a file?
Please use CODE tags as required by forum rules! (5 Replies)
Discussion started by: cogiz
5 Replies
10. Shell Programming and Scripting
I have an array code and output is below:
echo $1
while read -r fline; do
echo "%%%%%%$fline%%%%%"
fmy_array+=("$fline")
done <<< "$1"
Output:
CR30903 YU0007 SRIL CR30903 Yogesh SRIL
%%%%%%CR30903 YU0007 SRIL%%%%%
%%%%%%CR30903 Yogesh SRIL%%%%%
... (8 Replies)
Discussion started by: mohtashims
8 Replies
LEARN ABOUT PHP
array_splice
ARRAY_SPLICE(3) 1 ARRAY_SPLICE(3)
array_splice - Remove a portion of the array and replace it with something else
SYNOPSIS
array array_splice (array &$input, int $offset, [int $length], [mixed $replacement = array()])
DESCRIPTION
Removes the elements designated by $offset and $length from the $input array, and replaces them with the elements of the $replacement
array, if supplied.
Note that numeric keys in $input are not preserved.
Note
If $replacement is not an array, it will be typecast to one (i.e. (array) $parameter). This may result in unexpected behavior when
using an object or NULL$replacement.
PARAMETERS
o $input
- The input array.
o $offset
- If $offset is positive then the start of removed portion is at that offset from the beginning of the $input array. If $offset is
negative then it starts that far from the end of the $input array.
o $length
- If $length is omitted, removes everything from $offset to the end of the array. If $length is specified and is positive, then
that many elements will be removed. If $length is specified and is negative then the end of the removed portion will be that many
elements from the end of the array. If $length is specified and is zero, no elements will be removed. Tip: to remove everything
from $offset to the end of the array when $replacement is also specified, use count($input) for $length.
o $replacement
- If $replacement array is specified, then the removed elements are replaced with elements from this array. If $offset and
$length are such that nothing is removed, then the elements from the $replacement array are inserted in the place specified by the
$offset. Note that keys in replacement array are not preserved. If $replacement is just one element it is not necessary to put
array() around it, unless the element is an array itself, an object or NULL.
RETURN VALUES
Returns the array consisting of the extracted elements.
EXAMPLES
Example #1
array_splice(3) examples
<?php
$input = array("red", "green", "blue", "yellow");
array_splice($input, 2);
// $input is now array("red", "green")
$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, -1);
// $input is now array("red", "yellow")
$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, count($input), "orange");
// $input is now array("red", "orange")
$input = array("red", "green", "blue", "yellow");
array_splice($input, -1, 1, array("black", "maroon"));
// $input is now array("red", "green",
// "blue", "black", "maroon")
$input = array("red", "green", "blue", "yellow");
array_splice($input, 3, 0, "purple");
// $input is now array("red", "green",
// "blue", "purple", "yellow");
?>
Example #2
array_splice(3) examples
The following statements change the values of $input the same way:
<?php
array_push($input, $x, $y);
array_splice($input, count($input), 0, array($x, $y));
array_pop($input);
array_splice($input, -1);
array_shift($input);
array_splice($input, 0, 1);
array_unshift($input, $x, $y);
array_splice($input, 0, 0, array($x, $y));
$input[$x] = $y; // for arrays where key equals offset
array_splice($input, $x, 1, $y);
?>
SEE ALSO
array_slice(3), unset(3), array_merge(3).
PHP Documentation Group ARRAY_SPLICE(3)