01-13-2015
Quote:
Originally Posted by
Don Cragun
Passing arrays to a function is tricky. The easier approach is to pass any fixed arguments as the 1st arguments to your functions and pass the filenames as a variable argument list with "${FILE_LIST_x[@]}".
I think that I am going to avoid passing the array for now and see how it goes. I can pass
LIST_SIZE0 and
LIST_SIZE* and let the function create each sub list. This will mean repeating
STATS_INPUT_FILENAMES=($(ls './'$SET'/'$FOLD'/'*'in.txt')) for each function call, but I will put up with that for now.
I guess I misunderstood the syntax for grabbing part of an array. The most important issue here is making sure that each file is on exactly one list. The second priority is making the lists as even as possible.
LMHmedchem
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
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
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
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
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
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
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
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
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
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
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
LEARN ABOUT DEBIAN
kwargs
Kwargs(3pm) User Contributed Perl Documentation Kwargs(3pm)
NAME
Kwargs - Simple, clean handing of named/keyword arguments.
VERSION
version 0.01
SYNOPSIS
use Kwargs;
# just named
my ($foo, $bar, baz) = kw @_, qw(foo bar baz);
# positional followed by named
my ($pos, $opt_one, $opt_two) = kwn @_, 1, qw(opt_one opt_two)
# just a hashref
my $opts = kw @_;
# positional then hashref
my ($one, $two, $opts) = kwn @_, 2;
WHY
?
Named arguments are good, especially when you take lots of (sometimes optional) arguments. There are two styles of passing named arguments
(by convention) in perl though, with and without braces:
sub foo {
my $args = shift;
my $bar = $args->{bar};
}
foo({ bar => 'baz' });
sub bar {
my %args = @_;
my $foo = $args{foo};
}
bar(foo => 'baz');
If you want to support both calling styles (because it should be mainly a style issue), then you have to do something like this:
sub foo {
my $args = ref $_[0] eq 'HASH' ? $_[0] : { @_ };
my $bar = $args->{bar};
}
Which is annoying, and not even entirely correct. What if someone wanted to pass in a tied object for their optional arguments? That could
work, but what are the right semantics for checking for it? It also gets uglier if you want to unpack your keyword arguments in one line
for clarity:
sub foo {
my ($one, $two, $three) =
@{ ref $_[0] eq 'HASH' ? $_[0] : { @_ } }{qw(one two three) };
}
Did I say clarity? HAHAHAHAHA! Surely no one would actually put something like that in his code. Except I found myself typing this very
thing, and That Is Why.
EXPORTS
Two functions (kw and kwn) are exported by default. You can also ask for them individually or rename them to something else. See
Sub::Exporter for details.
kw(@array, @names)
Short for "kwn(@array, 0, @names)"
kwn(@array, $number_of_positional_args, @names)
Conceptually shifts off n positional arguments from array, then figures out whether the rest of the array is a list of key-value pairs or a
single argument (usually, but not necessarily, a hashref). If you passed in any @names, these are used as keys into the hash, and the
values at those keys are appended to any positional arguments and returned. If you do not pass @names, you will get a hashref (or whatever
the single argument was, like a tied object) back.
Note that if the single argument cannot be dereferenced as a hashref, this can die. No attempt is made by this module to handle the
exception.
AUTHOR
Paul Driver <frodwith@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Paul Driver <frodwith@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
perl v5.12.4 2011-01-24 Kwargs(3pm)