Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Pure Perl Internals (with Pure Perl Segfaults)

by diotalevi (Canon)
on Mar 11, 2004 at 23:54 UTC ( #336029=note: print w/replies, xml ) Need Help??

in reply to Pure Perl Internals (with Pure Perl Segfaults)

Why not use B and Devel::Peek and maybe Devel::Pointer::PP? In fact, does this work anyplace that Emily Dickenson in perl doesn't? It looks like Brian was assuming a standard layout in memory but I don't think this is portable to big endian cpus or to compilers with different packing or reordering.
  • Comment on Re: Pure Perl Internals (with Pure Perl Segfaults)

Replies are listed 'Best First'.
Re: Re: Pure Perl Internals (with Pure Perl Segfaults)
by Ovid (Cardinal) on Mar 12, 2004 at 00:04 UTC

    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.


    New address of my CGI Course.

      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... :-)
      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.....


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://336029]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2018-04-20 05:56 GMT
Find Nodes?
    Voting Booth?