03-27-2009
Quote:
Originally Posted by
pludi
@_ is the automagically created array containing all calling parameters (the array that you use when you access $_[x]). And if there's more than one array to pass around, refs are definitely the way to go, unless you have some other way to discern one array from the other.
I agree with pludi. If you have more than one array, or even really just one array, use references as I showed in my other post. As far as @_ goes, he explained it well enough so I will leave it at that.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Passing a array to a function, a basic feature in modern language, seems to be only possible in KSH. Not in BASH. Depite all my efforts I couldn't come to a solution. See the following examples:
It works perfectly in KSH:
#!/usr/bin/ksh
function print_array {
# assign array by indirect... (3 Replies)
Discussion started by: ripat
3 Replies
2. Shell Programming and Scripting
Hi ,
I have three funcions f1, f2 and f3 .
f1 calls f2 and f2 calls f3 .
I have a global variable "period" which i want to pass to f3 .
Can i pass the variable directly in the definition of f3 ?
Pls help .
sars (4 Replies)
Discussion started by: sars
4 Replies
3. Shell Programming and Scripting
Hi there,
I am trying to call a shell script from a Perl script. here is the code:
@args = ("sh", "someshellprg.sh", "a file handler", "an array");
system(@args) == 0
or die "system @args failed: $?";
in the shell program, I examine if the arguments exits using:
if
then echo... (5 Replies)
Discussion started by: pinkgladiator
5 Replies
4. UNIX for Dummies Questions & Answers
Hi experts,
I am here again with another Issue.
I need to pass the array as parameter / argument to another script.
I tried it as follows . ( I got this idea from the link )
$ cat test1.sh
#! /usr/bin/ksh
set -a arr1
echo "...In Test1...."
arr1="APPS_DEV"
arr1="TEST_DEV"
echo... (16 Replies)
Discussion started by: rajavu
16 Replies
5. Shell Programming and Scripting
Hi All,
I am trying to pass an argument called "Pricelist" to a Perl function, then the function will open and print out the contents of the file named "Pricelist". But i can't seem to do it using my below code. Can any expert give some advice?
#!/usr/local/bin/perl
$DATABASE =... (1 Reply)
Discussion started by: Raynon
1 Replies
6. Shell Programming and Scripting
Hi,
I'm trying to write a function that reassigns an array to
another local array but the method used in reassigning
the array reformats the contents of the array which is
what I am trying to prevent.
The method used to load a file into an array works as
expected and the entire array is... (4 Replies)
Discussion started by: ASGR
4 Replies
7. Programming
Hi.
I have a problem with passing two dimensional array to a function.
First, let me show my code to explain what i am going to do:
I have function:void initialize_board(char board);which is supposed to modify content of passed array. I have read here: Question 6.18 how such arrays should be... (3 Replies)
Discussion started by: Shang
3 Replies
8. Programming
this is my code to try and prinnt out a deck of cards. the print function worked when used inside main without being a function but now i cant get it to work as a function probably since i dont know how to pass a struct array in c. I gave it a shot but i keep getting an assortment of errors. The... (0 Replies)
Discussion started by: bjhum33
0 Replies
9. Shell Programming and Scripting
my $sysdate = strftime('%Y-%m-%d', localtime );
biDeriveByDate('Table_Str',$sysdate,\@lIndx,\@lResVals)
In a perl script, when I'm trying to pass $sysdate to some external function it's not working since $sysdate is passed as a string mentioned above but my function is expecting a date value... (1 Reply)
Discussion started by: Devesh5683
1 Replies
10. Shell Programming and Scripting
Hello All,
I would like to ask help from you on how to pass variable value from a function that has been called inside the function. I have created below and
put the variables in " ". Is there another way I can do this? Thank you in advance.
readtasklist() {
while read -r mod ver... (1 Reply)
Discussion started by: aderamos12
1 Replies
array(3) Library Functions Manual array(3)
NAME
array - The array library interface
SYNTAX
#include <array.h>
DESCRIPTION
An allocated array variable keeps track of
o a (nonzero) pointer to a dynamically allocated region of memory;
o the number of bytes allocated (always positive); and
o the number of bytes initialized (between 0 and the number of bytes allocated).
There are two other possibilities for the state of an array variable: unallocated and failed. In both cases, there is no dynamically allo-
cated region of memory.
A new array variable is normally created as a static variable:
#include "array.h"
static array x;
At this point it is unallocated. The array library provides various allocation and inspection functions.
A new array variable can also be created dynamically. It must be initialized to all-0, meaning unallocated, before it is given to any of
the array functions. It must be returned to the unallocated (or failed) state, for example with array_reset, before it is destroyed. These
rules prevent all memory leaks.
Expansion and inspection
array x;
t* p1 = array_allocate(&x,sizeof(t),pos);
t* p2 = array_get(&x,sizeof(t),pos);
t* p3 = array_start(&x);
int64 len = array_length(&x,sizeof(t));
int64 bytes = array_bytes(&x);
Truncation and deallocation
array x;
array_truncate(&x,sizeof(t),len);
array_trunc(&x);
array_reset(&x);
array_fail(&x);
Comparison
array x;
array y;
if (array_equal(&x,&y))
/* arrays are equal... */
Concatenation
array x;
array y;
array_cat(&x,&y);
array_catb(&x,"fnord",5);
array_cats(&x,"fnord");
array_cats0(&x,"fnord"); /* also append the */
array_cat0(&x); /* append */
array_cate(&x,"fnord",1,4); /* append "nor" */
ORIGINAL API DEFINITION
http://cr.yp.to/lib/array.html
SEE ALSO
array_get(3), array_start(3), array_fail(3)
array(3)