returning multiple values

Thanks for all your help earlier.  I am doing much better now.  1/3 of my
script actually passes the tests now!  But I seem to be stuck again.

This sub is supposed to take a string and parse it into another string and
2 integers.  I get the new string back but not the integers, any ideas?

It passes the first test:
print "not " unless defined &parse_range;
print "ok 2\n";

On the second test for this sub I get:
Failed 1/1 test scripts, 0.00% okay. 1/5 subtests failed, 80.00% okay.
*** Error code 29

Belinda

<snip excess code>
void
parse_range (char * str, char * chrom, int st, int stp) {
      sscanf(str, "%[chrXY1234567890]%*[:]%d%*[-]%d", chrom, &st, &stp);
}
/**** End of subroutine parse_range ****/

<snip some more code>
void
parse_range(str, chrom, st, stp)
        char *str;
        char *chrom = NO_INIT;
        int  st = NO_INIT;
        int  stp = NO_INIT;
CODE:
        parse_range(str, chrom, st, stp);
OUTPUT:
        chrom
        st
        stp


0
giardine
11/29/2002 5:39:00 PM
perl.xs 808 articles. 0 followers. Follow

1 Replies
418 Views

Similar Articles

[PageSpeed] 59
Get it on Google Play
Get it on Apple App Store

On Fri, Nov 29, 2002 at 12:39:00PM -0500, Belinda M. Giardine wrote:
> Thanks for all your help earlier.  I am doing much better now.  1/3 of my
> script actually passes the tests now!  But I seem to be stuck again.

Excellent news.

> This sub is supposed to take a string and parse it into another string and
> 2 integers.  I get the new string back but not the integers, any ideas?
> 
> It passes the first test:
> print "not " unless defined &parse_range;
> print "ok 2\n";

Which is simply testing that the sub exists, so I'd be very alarmed if
that failed.

> On the second test for this sub I get:
> Failed 1/1 test scripts, 0.00% okay. 1/5 subtests failed, 80.00% okay.
> *** Error code 29

Not knowing what the test does, I can only flag the following warning signs.

> 
> <snip excess code>
> void
> parse_range (char * str, char * chrom, int st, int stp) {
>       sscanf(str, "%[chrXY1234567890]%*[:]%d%*[-]%d", chrom, &st, &stp);
> }

st and stp are on the stack here, so they value you're pushing into
them with scanf isn't taking in the calling sub.  You can fix that by
passing pointers.

void
parse_range (char *str, char *chrom, int *st, int *stp) {
     sscanf(str, "%[chrXY1234567890]%*[:]%d%*[-]%d", chrom, st, stp);
}

And then flater doing this:

         parse_range(str, chrom, &st, &stp);


Also, here you're doing a very C-like returning of values, so your
Perl code looks like C< parse_range($str, $chrom, $st, $stp); >.  

The more common idiom for returning mutiple values is would typically
fall out as:

void
parse_range(str)
        char *str;
PPCODE:
        char chrom[SOME_MAX_SIZE];
        int  st, stp;

        parse_range(str, chrom, st, stp);
	XPUSHs(sv_2mortal(newSVpv(chrom, 0)));
	XPUSHs(sv_2mortal(newSViv(st)));
	XPUSHs(sv_2mortal(newSViv(stp)));

enabling you to write the more natural:

my ($chrom, $st, $stp) = parse_range($str);

Though I do hope I've not just instructed you in the sucking of eggs.

-- 
Richard Clamp <richardc@unixbeard.net>
0
richardc
11/29/2002 6:03:04 PM
Reply:

Similar Artilces:

Returning multiple values
Hi! I use "Return var" to return a single value from my web service. So I need to know how to return multiple values instead of a single one. Can you help me? Thanks a lot. Please see below example, it could lead to solve your problem! http://www.w3coder.com/contest/examples/WSObjMultiArr.asmx source code at http://www.w3coder.com/contest/examples/WSObjMultiArr.asmx.txt Sreedharhttp://www.w3coder.orgweblog http://weblogs.asp.net/skoganti...

Multiple Return Values
I have a situation where I need two values (both are integers) returned from a stored procedure. (SQL 2000) Right now, I use the statement "return @@Identity" for a single value, but there is another variable assigned in the procedure, @NewCounselingRecordID that I need to pass back to the calling class method. I was thinking of concatenating the two values as a string and parsing them out after they are passed back to the calling method. It would look something like "21:17", with the colon character acting as a delimiter. However, I feel this solution is kludg...

What is the best way to make a subroutine visible to multiple .aspx documents and return multiple values
I have a complex subroutine that has 10 input values and needs to return 10 result values.  What is the best way to make this visible to multiple .aspx documents? Thanks,David  you can try with custom entity objects as return type. Entity class has a property of all results.    This depends on your architecture.  If this is just a common subroutine that is not related to a class, you could just create a class of utility methods.  (I still say class because I'm anti-module in VB).  If you declare the subroutine as public/friend with a static ...

how to return return value?
imagine there was an sp beyond your control (i.e. you cannot use output parameters to obtain the value) but you had to catch the return value submitted by "return <value>" how would you do that? execute returns boolean executeUpdate returns int, but obviously not the return value but rows affected or so what the..? -- pat Hello Pat, For the return value you wills till need to register it as an output parameter, no matter how you execute the sproc. You would need to send the SQL as something like: {? = call sprocName(?, ?, ....)} The for the retu...

return multiple values from subroutine
i want to return multiple values from a subroutine. all the examples i have seen show just a single value (sometimes an array) being returned, and until now i have been creating an array just for this purpose. what i would like to do is what i have done in the simple code below (that obviously doesn't work). i have a couple of questions : 1. can "return" be used to return multiple values or do they all have to be collected into one structure like an array? 2. is there any way i can do a multiple assignment like i tried to do in the last line below? i a...

Multiple return values in SpiderMonkey
How can we create a multiple return value in SpiderMonkey? See http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7#Multiple-value_returns Franky. On Dec 24, 2007 11:00 AM, Franky Braem <f.braem@skynet.be> wrote: > How can we create a multiple return value in SpiderMonkey? See > http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7#Multiple-value_returns Just create an array and return it. Mike ...

xs for object returned by value
Hello, I've got a function in a wx object that I'm writing XS for that returns a another object, which doesn't inherit from any wx classes, by value (not a pointer to object), meaning the O_WXOBJECT, O_NON_WXOBJECT, T_PTROBJ and T_PTRREF typemaps give the error "cannot convert 'wxWebViewDOMElementInfo' to 'const void *' in argument passing" error. Is there a 'right' / best way for returning objects by value from C++? -- Ryan ...

Returning Multiple Value Attributes
--LTeJQqWS0MN7I/qa Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi List, I am using Net::LDAP and i am trying to return an attribute in a d= n that has multiple values. When I do the search and use $entry->get_value(= $attr ) it only returns the one value. Is there a way returning multiple a= ttribute values? Many thanks --=20 slr, ISP Systems Specialist Telkom Internet #qmail-ldap @ irc.freenode.net This message has been made from 100% recycled bits. ----BEGIN GEEK CODE BLOCK----- Version: 3.12...

Returning multiple values from a function...
Hi all, I know this is probably a silly question, but I thought I'd throw it out anyway. I typically call functions that are housed in separate scripts from my PD templates. Is it possible to return more than one value from those functions? That way, I could consolidate my sql queries in seperate scripts, return several values and still keep the number of queries to a minimum.. TIA Scott The only way I can think of to do this is to create an object of some sort to keep the multiple return values. Earl Scott W wrote: > > Hi all, > > I know thi...

Return Multiple values from a window
Hi, How to return multiple values from a window, without using a structure or global variable? Any help in this regard will be appreciated. Thanks, Sindhu. ---== Posted via the PFCGuide Web Newsreader ==--- http://www.pfcguide.com/_newsgroups/group_list.asp How about passing back concatenated string with some character sequence (for example tab) acting as a separator. /ck "Sindhu" <sindhuvid@yahoo.co.in> wrote in message news:#BobnvfFCHA.290@forums.sybase.com... > Hi, > > How to return multiple values from a window, without using a str...

Return multiple values from a class
How do I get two values 1 boolean and 1 string from a Class I am doing a 3 tier application .In my DAL class I have a function that does update of 2 tables and I want to gather some information from both the updates How do I do it Thanks Your function or method can return one of the items as its return value, and the other can be returned as an output variable.Thanks, EdMicrosoft MVP - ASP/ASP.NET but how to declare an output variable in a function In C#, use the "out" keyword. http://msdn2.microsoft.com/en-us/library/t3c3bfhx(VS.80).aspx In VB.Net, pass the argument B...

webservice returns multiple values
Hi Friends! i have a webmethod which takes two inputparameters and returns one value to the calling application. Now i have to  return two values to the calling application. simply how to return two variables through a webmethod which accpts two input parameters.... Thanks in Advance!!! Hi, with ASP.NET webservices, you have simple data types and complex data types which can be used to passed to and returned from web methods. You could return an array or use a dataset. Please read for more info http://www.dotnetjunkies.ddj.com/quickstart/aspplus/doc/webservicetypes.aspxVishal H...

function returning multiple values!!! ???
Please help, I really need to know how to have a function that returns multiple values like this one returns only 1 single value.. Public Function RetrieveMemberInfo(ByVal inputUID As String) As String .... End Function Public Function RetrieveMemberInfo(ByVal inputUID As String,ByRef Return2 as String) As String .... End Function In this case, Return2 is an additional value "returned". Better, return a structure or class that encapsulates all the values you need to return.Starting with ASP.NET 2.0? Look at:Programming Microsoft Web Forms My Bl...

How to handle multiple return values?
Hi, Currently, argument passing is done using the same code as return value passing (with :flat and :slurpy stuff). But there's a small difference: argument passing can generate more errors than return value passing. For example, if you pass 2 args and a function wants 1, that's an error. Not so for returning. If you do $P0 = myfun(), where myfun returns two values, then the first value is stored in $P0 and that's it. This is wanted behaviour for a lot of languages, I think. A lesser known fact is probably that if myfun returns no values, then $P0 is unchanged. Very ...

Web resources about - returning multiple values - perl.xs

Returning - Wikipedia, the free encyclopedia
In retail , returning is the process of a customer taking previously purchased merchandise back to the retailer, and in turn, receiving a cash ...

Mark Zuckerberg Returning To TechCrunch Disrupt
Facebook Co-Founder and CEO Mark Zuckerberg took the stage at last year’s TechCrunch Disrupt conference in San Francisco, where he discussed ...

How-to: Improve the Experience for Returning Users
... – your inbox, your favorite news sources, or your friends’ activity. If you’ve integrated Facebook Login on your website, you can give returning ...

Search Twitter - emilia-clarke-not-returning
Sign in Sign up Search Refresh K. @ kikeurbina 1h Muy malas noticias: 'GAME OF THRONES' STAR EMILIA CLARKE (DAENERYS) NOT RETURNING FOR SEASON ...

Is the Returning CEO a Trend?
... well be wondering if it is a new trend for boards to reach back into their alumni ranks to bring back a CEO when a company is in Is the Returning ...

Returning fire - Flickr - Photo Sharing!
A U.S. Army soldier with the 101st Airborne Division returns fire with a M249 light machine gun during combat operations in the valley of Barawala ...

Marines Celebrate Returning Home With a Huge Pillow Fight Aboard the Airplane - YouTube
Visit http://WelcomeHomeBlog.com for more surprise military homecomings! In this clip, a group of marines celebrate their safe return home from ...

WWE’s Daniel Bryan on WWE 2K16, facing Brock Lesnar at WrestleMania, returning to the ring and life on ...
The four-time WWE world champion discusses whether it is right for Stone Cold Steve Austin to be the cover star of WWE 2K16, as well as who he ...

Damn Fine News of the Day: Kyle MacLachlan is Returning to ‘Twin Peaks’
In case you missed it, David Lynch announced on Twitter Monday that Kyle MacLachlan will reprise his role as Special Agent Dale Cooper in the ...

Injury not enough to keep official caught in crossfire from returning to action
The NRL match official caught in the crossfire of angry Bulldogs fans says he has no intention of stepping down from his role on the sidelines. ...

Resources last updated: 12/7/2015 5:26:47 PM