Returning and capturing multiple return values from a function
Hi
I am pretty confused in returning and capturing multiple values
i have defined a function which should return values "total, difference"
i have used as
I have invoked this function as
calc 5 8
Now i need the value of $total and $diff after the function is being invoked..
Please help..
Last edited by vbe; 04-09-2013 at 06:43 AM..
Reason: code tags
hi
how can I return multiple values from a C function. I tried the following:
#include <stdio.h>
void foo(int id, char *first_name, char *last_name)
{
/*
this is just an example to illustrate my problem... real code makes
use of the "id" parameter.
*/
first_name = (char... (8 Replies)
I am working on a C/Unix application from last 2 years which communicates with other systems using proprietary format of my client. We have a function written in C which returns integer, which is response from other system to the request message initiated by my system. This return value is then... (1 Reply)
i have an oracle function which returns two values, one is the error message if the function encounters anything and another one which returns a number
i need to capture both
and pass it on to unix shell script
how to do it (2 Replies)
Hi,
I have a script which does something like the below:
execute_some_script.sh $arg1 $arg2 `exec-some-cmd`
if then;
do something
else
do something else
fi
However, during some cases, there is an error saying:
line xxx: [: too many arguments
at the line number which has... (5 Replies)
Hi,
I need to retrun multiple values
function errorFileCreation
{
echo "Before"
return -1 "Siva";
echo "Aftyer"
}
echo ${?} - This can be used to getting first value.
how can i get second one.
Advance Thanks...
Shiv (3 Replies)
I am using a for loop to copy files from say DIR1 and DIR2 to DIR3.I have to check whether files are copied from DIR1 and DIR2 and print the respective message.
@path=("$DIR1","$DIR2");
foreach (@path) {
$rc=system("cp $_/*xml $DIR3");
if ($rc == 0)
{
print "Files were copied... (1 Reply)
Hello,
I need to capture multiple values from user input and do not know how to do it. I'm writing a script to delete old files, but want to give the option to keep some by asking the user.
This is what my output looks like...
Old files to be deleted...
1 file1
2 file2
Then this bit of... (3 Replies)
I've been trying to write a command-line function to grab a website's MX records and their ip addresses. The code below works with domains that only have one MX record:
function kmx { mx=`host -t MX $1 | awk '{ print $7 }'`;
ip=`host $mx | sed '/IPv6/d;/handled/d' | awk '{ print $4 }'`; ... (8 Replies)
Hi
I have a code as the following
#!/usr/bin/ksh
set -x
row()
{
a=$1
b=$2
c=$(($a + $b))
d=$(($a * $b))
echo $a $b
}
e=`row 2 3`
set $e
echo "The value of c is $c"
echo "The value of d is $d"
My requirement is I need to pass two arguments to a function and return two values... (5 Replies)
Hi,
I have a small part of a project which is done as a bash script. bash was selected as an portability issue that works out of the box. In this script I have an exec shell-function, a wrapper around arbitrary commands. I want to have STDOUT, as an addon STDERR and the EXIT-CODE of a specified... (5 Replies)
Perl::Critic::Policy::RegularExpressions::ProhibitUnusedUseruContributed Perl Perl::Critic::Policy::RegularExpressions::ProhibitUnusedCapture(3pm)NAME
Perl::Critic::Policy::RegularExpressions::ProhibitUnusedCapture - Only use a capturing group if you plan to use the captured value.
AFFILIATION
This Policy is part of the core Perl::Critic distribution.
DESCRIPTION
Perl regular expressions have multiple types of grouping syntax. The basic parentheses (e.g. "m/(foo)/") captures into the magic variable
$1. Non-capturing groups (e.g. "m/(?:foo)/" are useful because they have better runtime performance and do not copy strings to the magic
global capture variables.
It's also easier on the maintenance programmer if you consistently use capturing vs. non-capturing groups, because that programmer can tell
more easily which regexps can be refactored without breaking surrounding code which may use the captured values.
CONFIGURATION
This Policy is not configurable except for the standard options.
CAVEATS
"qr//" interpolation
This policy can be confused by interpolation of "qr//" elements, but those are always false negatives. For example:
my $foo_re = qr/(foo)/;
my ($foo) = m/$foo_re (bar)/x;
A human can tell that this should be a violation because there are two captures but only the first capture is used, not the second. The
policy only notices that there is one capture in the regexp and remains happy.
"@-", "@+", $LAST_MATCH_START and $LAST_MATCH_END
This policy will only recognize capture groups referred to by these variables if the use is subscripted by a literal integer.
$^N and $LAST_SUBMATCH_RESULT
This policy will not recognize capture groups referred to only by these variables, because there is in general no way by static analysis to
determine which capture group is referred to. For example,
m/ (?: (A[[:alpha:]]+) | (Nd+) ) (?{$foo=$^N}) /smx
makes use of the first capture group if it matches, or the second capture group if the first does not match but the second does.
CREDITS
Initial development of this policy was supported by a grant from the Perl Foundation.
AUTHOR
Chris Dolan <cdolan@cpan.org>
COPYRIGHT
Copyright (c) 2007-2011 Chris Dolan. Many rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license
can be found in the LICENSE file included with this module
perl v5.14.22012-06-07Perl::Critic::Policy::RegularExpressions::ProhibitUnusedCapture(3pm)