On Sep 17, 2004, at 5:32 AM, Reinhard Pagitsch wrote:
Nick Ing-Simmons wrote:
Reinhard Pagitsch <[EMAIL PROTECTED]> writes:Because I load a binary file and parse its content. The file has records which I have to parse for specific informations which I do in a XS function. If I could call the split from my XS function maybe I could use it.I not want to pass an arry to my XS, I want to get back an array.
Why? Perl's split is very flexible and well optimized for creating perl arrays from strings.
what you describe still doesn't preclude using perl's split.
sub get_record_as_ary { # an xs function parses the record from the file, converts # ebcdic to ascii, and replaces junk with whitespace. my $string = _get_record_as_string (); # now tokenize on the whitespace and return the pieces. return split /\s+/, $string; }
you *can* use perl's split from xs, but it's not very fun --- you have to basically set up the stack and use eval_pv(), which is a lot harder than just returning the string and manipulating it in perl.
the function warn_of_ignored_exception() in http://cvs.sourceforge.net/viewcvs.py/gtk2-perl/gtk2-perl-xs/Glib/ GClosure.xs?rev=1.30&view=auto (near the bottom) illustrates the kinds of hoops you have to jump through to use perl's native regex substitutions from C/XS.
it's a well-accepted practice to put in XS only the stuff you can't do in perl (or can't do as easily), and wrap that up with perl subroutines.
-- Holy crap, dude, we have kids! -- Elysse, six days after giving birth to twins