Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: Pure Perl Internals (with Pure Perl Segfaults)

by Ovid (Cardinal)
on Mar 12, 2004 at 00:04 UTC ( #336033=note: print w/ replies, xml ) Need Help??


in reply to Re: Pure Perl Internals (with Pure Perl Segfaults)
in thread Pure Perl Internals (with Pure Perl Segfaults)

It's pure Perl (only your last example is) and it's the start of a clean, OO method of walking through Perl's structs. Frankly, I can't think of any reason I would use this (Ingy needed a pure Perl method of determining if a scalar contained an integer or a string), but it's fun (to me).

As for portability, Ingy admits that this is alpha code, but he's using Config to try to make it as portable as possible.

Cheers,
Ovid

New address of my CGI Course.


Comment on Re: Re: Pure Perl Internals (with Pure Perl Segfaults)
Re: Re: Re: Pure Perl Internals (with Pure Perl Segfaults)
by diotalevi (Canon) on Mar 12, 2004 at 00:08 UTC

    Eh. Sure B is compiled but by being so, it doesn't have to guess at how the compiler that constructed the interpreter arranged things in memory nor does it have to care about big vs little endian. If you do it in pure perl then you have to solve both of those problems as well.

    ... Oh I see. That's nicely done.

      Well, considering that pack and unpack were written with exactly this sort of thing in mind in the first place... :-)
        Shirley, there's a a backromyth in your soda!
Re3: Pure Perl Internals (with Pure Perl Segfaults)
by blakem (Monsignor) on Mar 18, 2004 at 06:50 UTC
    Ingy needed a pure Perl method of determining if a scalar contained an integer or a string
    While his results are cool, he could have saved a lot of work if he'd asked around to see if anyone had already found a solution to this problem (note the unary "~", it's important)
    sub is_integer { ~$_[0] !~ /\D/ }
    Here are some tests to demonstrate that it works:
    #!/usr/bin/perl -wT use strict; use Test; BEGIN { plan tests => 345 } for my $num (-56789, -300, -1, 0..100, 5345, 6574572, 23457356) { ok( is_integer($num) ); my $string = "$num"; ok( not is_integer($string) ); } for my $string ((map { chr($_) } 0..127), 'dog', 'cat', 'mouse') { ok( not is_integer($string) ); } sub is_integer { ~$_[0] !~ /\D/ }
    I found the is_integer() implementation in my cool-snippets-from-perlmonks directory, but can't seem to find the original thread.....

    -Blake

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://336033]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2014-09-20 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (151 votes), past polls