Sponsored Content
Top Forums Shell Programming and Scripting Split list of files into an array and pass to function Post 302931522 by RudiC on Tuesday 13th of January 2015 01:50:43 PM
Old 01-13-2015
I can see two ways to pass an array to a function, at least for my bash 4.3.30:
- pass the element count and then the elements scr1.sh A B ${#LIST[@]} ${LIST[@] C D }, run a for loop to assign to a local array
- pass the array like scr1.sh A B "${LIST[*]}" C D ; define local array like ARR=($3)
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can we pass array with call by value in function

I want to pass an array in my function, And my function will be changing the elements of the array in the fuction, but it should not affect the values in my array variable of main function (1 Reply)
Discussion started by: ranjithpr
1 Replies

2. Shell Programming and Scripting

Array split function & hashes

Hi, If this is the array that is being returned to me: How would I get the values for each of the 3 records? This works for 1 Record: foreach $item (@results) { ($id, $id2, $name, $date, $email) = split(/\|/, $item, 5); print "$name<br>"; } (2 Replies)
Discussion started by: novera
2 Replies

3. Shell Programming and Scripting

How to pass an array from SHELL to C function

Hi, I have an output generated from a shell script like; 0x41,0xF2,0x59,0xDD,0x86,0xD3,0xEF,0x61,0xF2 How can I pass this value to the C function, as below; int main(int argc, char *argv) { unsigned char hellopdu={above value}; } Regards Elthox (1 Reply)
Discussion started by: elthox
1 Replies

4. Shell Programming and Scripting

Find and split the list of files with suffiz of seg**

Hi,. I am writing a script to get the new files and split them. Requirement Find the new files under the path "/wload/scmp/app/data/OAS" (There are 5 sub folders). Gunzip the files which are having .gz suffix. Put the list of files in the filename in the format... (0 Replies)
Discussion started by: Satish Shettar
0 Replies

5. Shell Programming and Scripting

Split the file and access that files through array and loop

Hi All, the below is my requirement.. i need to split the file based on line and put that files in a array and need to access that files through loop finally i should send the files through mail.. how can we achieve this ..I am new to shell script please guide me.. I am using KSH.. ... (11 Replies)
Discussion started by: kalidoss
11 Replies

6. Shell Programming and Scripting

How to pass an array to a function in shell script.?

hi, I have a array say SAP_ARRAY="s1.txt" SAP_ARRAY="s2.txt" how can i pass this full array to a function. here is the sample code i am using.. CHECK_NO_FILES() { FARRAY=$1 echo "FARRAY = $FARRAY" echo "FARRAY = $FARRAY" ............... (5 Replies)
Discussion started by: Little
5 Replies

7. Shell Programming and Scripting

Question about sorting -- how to pass an array to a function

Hi, guys I just wanted to sort the elements of an array ascendingly. I know the following code does work well: array=(13 435 8 23 100) for i in {0..4} do j=$((i+1)) while ] do if } -le ${array} ]] then : else min=${array} ${array}=${array} ${array}=$min fi... (5 Replies)
Discussion started by: franksunnn
5 Replies

8. Shell Programming and Scripting

Pass array to a function and display the array

Hi All I have multiple arrays like below. set -A val1 1 2 4 5 set -A val2 a b c d . . . Now i would like to pass the individual arrays one by one to a function and display/ do some action. Note : I am using ksh Can you please advise any solution... Thanks in advance. (7 Replies)
Discussion started by: Girish19
7 Replies

9. Shell Programming and Scripting

Pass an array to awk to sequentially look for a list of items in a file

Hello, I need to collect some statistical results from a series of files that are being generated by other software. The files are tab delimited. There are 4 different sets of statistics in each file where there is a line indicating what the statistic set is, followed by 5 lines of values. It... (8 Replies)
Discussion started by: LMHmedchem
8 Replies

10. Shell Programming and Scripting

How to pass and read an array in ksh shell script function.?

I'm able to read & print an array in varaible called "filelist" I need to pass this array variable to a function called verify() and then read and loop through the passed array inside the function. Unfortunately it does not print the entire array from inside the funstion's loop. #/bin/ksh... (5 Replies)
Discussion started by: mohtashims
5 Replies
Tie::Array(3pm) 					 Perl Programmers Reference Guide					   Tie::Array(3pm)

NAME
Tie::Array - base class for tied arrays SYNOPSIS
package Tie::NewArray; use Tie::Array; @ISA = ('Tie::Array'); # mandatory methods sub TIEARRAY { ... } sub FETCH { ... } sub FETCHSIZE { ... } sub STORE { ... } # mandatory if elements writeable sub STORESIZE { ... } # mandatory if elements can be added/deleted sub EXISTS { ... } # mandatory if exists() expected to work sub DELETE { ... } # mandatory if delete() expected to work # optional methods - for efficiency sub CLEAR { ... } sub PUSH { ... } sub POP { ... } sub SHIFT { ... } sub UNSHIFT { ... } sub SPLICE { ... } sub EXTEND { ... } sub DESTROY { ... } package Tie::NewStdArray; use Tie::Array; @ISA = ('Tie::StdArray'); # all methods provided by default package main; $object = tie @somearray,'Tie::NewArray'; $object = tie @somearray,'Tie::StdArray'; $object = tie @somearray,'Tie::NewStdArray'; DESCRIPTION
This module provides methods for array-tying classes. See perltie for a list of the functions required in order to tie an array to a package. The basic Tie::Array package provides stub "DESTROY", and "EXTEND" methods that do nothing, stub "DELETE" and "EXISTS" methods that croak() if the delete() or exists() builtins are ever called on the tied array, and implementations of "PUSH", "POP", "SHIFT", "UNSHIFT", "SPLICE" and "CLEAR" in terms of basic "FETCH", "STORE", "FETCHSIZE", "STORESIZE". The Tie::StdArray package provides efficient methods required for tied arrays which are implemented as blessed references to an "inner" perl array. It inherits from Tie::Array, and should cause tied arrays to behave exactly like standard arrays, allowing for selective overloading of methods. For developers wishing to write their own tied arrays, the required methods are briefly defined below. See the perltie section for more detailed descriptive, as well as example code: TIEARRAY classname, LIST The class method is invoked by the command "tie @array, classname". Associates an array instance with the specified class. "LIST" would represent additional arguments (along the lines of AnyDBM_File and compatriots) needed to complete the association. The method should return an object of a class which provides the methods below. STORE this, index, value Store datum value into index for the tied array associated with object this. If this makes the array larger then class's mapping of "undef" should be returned for new positions. FETCH this, index Retrieve the datum in index for the tied array associated with object this. FETCHSIZE this Returns the total number of items in the tied array associated with object this. (Equivalent to "scalar(@array)"). STORESIZE this, count Sets the total number of items in the tied array associated with object this to be count. If this makes the array larger then class's mapping of "undef" should be returned for new positions. If the array becomes smaller then entries beyond count should be deleted. EXTEND this, count Informative call that array is likely to grow to have count entries. Can be used to optimize allocation. This method need do nothing. EXISTS this, key Verify that the element at index key exists in the tied array this. The Tie::Array implementation is a stub that simply croaks. DELETE this, key Delete the element at index key from the tied array this. The Tie::Array implementation is a stub that simply croaks. CLEAR this Clear (remove, delete, ...) all values from the tied array associated with object this. DESTROY this Normal object destructor method. PUSH this, LIST Append elements of LIST to the array. POP this Remove last element of the array and return it. SHIFT this Remove the first element of the array (shifting other elements down) and return it. UNSHIFT this, LIST Insert LIST elements at the beginning of the array, moving existing elements up to make room. SPLICE this, offset, length, LIST Perform the equivalent of "splice" on the array. offset is optional and defaults to zero, negative values count back from the end of the array. length is optional and defaults to rest of the array. LIST may be empty. Returns a list of the original length elements at offset. CAVEATS
There is no support at present for tied @ISA. There is a potential conflict between magic entries needed to notice setting of @ISA, and those needed to implement 'tie'. AUTHOR
Nick Ing-Simmons <nik@tiuk.ti.com> perl v5.16.2 2012-10-11 Tie::Array(3pm)
All times are GMT -4. The time now is 08:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy