in reply to Re: Parse float from string
in thread Parse float from string

The XS code is trivial (aside from the name of the module - I used a dummy for illustration purposes :-)):
#include "EXTERN.h" #include "perl.h" #include "XSUB.h" MODULE = Foo::IsNum PACKAGE = Foo::IsNum int looks_like_number(sv) SV *sv
However I don't think this would quite solve the problem.
In particular it returns false when testing the string "123abc" (which makes sense, this isn't a number). So to extract the number I think you still need to consider using a regexp.

email me or /msg me if you'd like to have the code to play around with...

Michael

Replies are listed 'Best First'.
Re: Re: Re: Parse float from string
by BrowserUk (Patriarch) on Nov 05, 2002 at 01:34 UTC

    Your right. It wouldn't help a great deal in this particular case.

    The problem I had trying to access it without resorting to XS came (I was reliably informed) because it (or at least the version exported by perl56.dll under AS/build633multi-threaded) requires that it is passed a pTHX_ SV* rather than a simple SV* as shown below and it isn't possible to get at one of those from within Perl itself. I could well be wrong on that, but I failed spectacularly for 3 days to achieve it.

    PERL_CALLCONV I32 Perl_looks_like_number(pTHX_ SV* sv);

    As for the XS. I am not, nor do I wish to be at this point, set up to go through the pain of building my own XS modules. I am managing to keep myself busy trying to learn the in's and out's of perl itself. A process which I am thoroughly enjoying. I don't wish (at this time) to pollute that joy by getting into the world of XS which I have seen several monks who's abilities I much respect, complain publicly (though possibly in part in jest) regarding the vaguries of using XS.

    Thanks a lot for the offer though. I wonder, but don't have enough insentive at this stage to research it, how hard it would be to create a module that would reliably work cross platform?

    Please excuse my ignorance if what you offered would do that, but I mean one that I could install with the need to compile it.


    Nah! Your thinking of Simon Templar, originally played by Roger Moore and later by Ian Ogilvy
      Thanks a lot for the offer though. I wonder, but don't have enough insentive at this stage to research it, how hard it would be to create a module that would reliably work cross platform?
      Well - I don't actually have a Win32 box that I could develop/test this on. And I personally don't have a use for such a module - I did this to illustrate that XS isn't very difficult for simple access to C routines (it can get hairy if you need to really access the perl guts, but that's another story.)

      Michael