Quoth
:
> "Sisyphus" <> wrote:
> >
> > D:\pscrpt\inline\>perl char2octal.pl
> > Use of uninitialized value in subroutine entry at char2octal.pl line 22.
> > \141\142\143\144\101\102\103\104
> > -----------------------------
> >
> > I'm sure it's one of those questions that will make me go "Doh!", but I
> > can't for the life of me see what is causing that "uninitialized"
> > warning. Any hints ? (I'm running perl 5.8.8 on Win32.)
>
> Ah, I forgot to turn on warnings and so never saw it.
>
> Apparently sv_catpvf, unlike .= operator, doesn't care for undefined
> values. So make that:
>
> ret = newSV(4*len);
> sv_setpv(ret, "");
> for (i=0; i<len; i++,s++) {
>
> I guess Inline warnings all get reported as being at subroutine entry?
Yes, as with all warnings thrown inside XS. The currently executing Perl
op is the sub call, so that's what you get: the whole XS sub is run as
part of the sub call op, which then returns rather than jumping to the
start of the sub as it would with Perl.
> For what it's worth, I've made another uglier one that is about twice again
> as fast. This is going to wrap like crazy:
>
> SV* sol32(SV* a) {
> static const char * cache[]={"\\000","\\001","\\002","\\003","\\004",
I wondered about that (in Perl, not in C); to make it a little less ugly
you could have
static const char cache[0x100][5]; /* c arrays confuse me

*/
void populate_cache (void) {
int i;
for (i=0; i<0x100; i++) {
Copy(form("\\%3o", i), cache[i], 5, char);
}
}
Ben
--
Outside of a dog, a book is a man's best friend.
Inside of a dog, it's too dark to read.
Groucho Marx