Sponsored Content
Top Forums Shell Programming and Scripting Perl Function Array Arguement Passing Post 302301639 by KevinADC on Friday 27th of March 2009 01:29:42 PM
Old 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

[BASH - KSH] Passing array to a function

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

Passing global variable to a function which is called by another function

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

Passing a file handler and an array from Perl to Shell Script

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

How to pass array as an arguement ?

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

Passing arguments to Perl Function

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

[bash] passing array to function

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

Passing two dimensional array to a function

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

[solved]help passing array of structs to function in c

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

Problem in passing date to external function from perl script.

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

Passing variable value in a function to be used by another function

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_UNIQUE(3) 							 1							   ARRAY_UNIQUE(3)

array_unique - Removes duplicate values from an array

SYNOPSIS
array array_unique (array $array, [int $sort_flags = SORT_STRING]) DESCRIPTION
Takes an input $array and returns a new array without duplicate values. Note that keys are preserved. array_unique(3) sorts the values treated as string at first, then will keep the first key encountered for every value, and ignore all following keys. It does not mean that the key of the first related value from the unsorted $array will be kept. Note Two elements are considered equal if and only if (string) $elem1 === (string) $elem2 i.e. when the string representation is the same, the first element will be used. PARAMETERS
o $array - The input array. o $sort_flags - The optional second parameter $sort_flags may be used to modify the sorting behavior using these values: Sorting type flags: o SORT_REGULAR - compare items normally (don't change types) o SORT_NUMERIC - compare items numerically o SORT_STRING - compare items as strings o SORT_LOCALE_STRING - compare items as strings, based on the current locale. RETURN VALUES
Returns the filtered array. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ |5.2.10 | | | | | | | Changed the default value of $sort_flags back to | | | SORT_STRING. | | | | | 5.2.9 | | | | | | | Added the optional $sort_flags defaulting to | | | SORT_REGULAR. Prior to 5.2.9, this function used | | | to sort the array with SORT_STRING internally. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 array_unique(3) example <?php $input = array("a" => "green", "red", "b" => "green", "blue", "red"); $result = array_unique($input); print_r($result); ?> The above example will output: Array ( [a] => green [0] => red [1] => blue ) Example #2 array_unique(3) and types <?php $input = array(4, "4", "3", 4, 3, "3"); $result = array_unique($input); var_dump($result); ?> The above example will output: array(2) { [0] => int(4) [2] => string(1) "3" } SEE ALSO
array_count_values(3). NOTES
Note Note that array_unique(3) is not intended to work on multi dimensional arrays. PHP Documentation Group ARRAY_UNIQUE(3)
All times are GMT -4. The time now is 06:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy