Stories
Slash Boxes
Comments

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

acme (189)

acme
  (email not shown publicly)
http://www.astray.com/

Leon Brocard (aka acme) is an orange-loving Perl eurohacker with many varied contributions to the Perl community, including the GraphViz module on the CPAN. YAPC::Europe was all his fault. He is still looking for a Perl Monger group he can start which begins with the letter 'D'.

Journal of acme (189)

Monday February 02, 2004
07:09 AM

perl source code

[ #17148 ]
Sometimes I wonder about the perl source code. So I was looking at what Perl_looks_like_number actually does. And the code is the following:

I32
Perl_looks_like_number(pTHX_ SV *sv)
{
    register char *sbegin;
    STRLEN len;

    if (SvPOK(sv)) {
   sbegin = SvPVX(sv);
   len = SvCUR(sv);
    }
    else if (SvPOKp(sv))
   sbegin = SvPV(sv, len);
    else
   return 1; /* Historic.  Wrong?  */
    return grok_number(sbegin, len, NULL);
}

Mmmm, funky backwards indenting and amusing comment with two returns in a row...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Blocks in C (Score:3, Informative)

    by davorg (18) <dave@dave.org.uk> on 2004.02.02 8:17 (#27963) Homepage Journal
    with two returns in a row
    Not quite. Single statement blocks in C don't need surrounding braces, so the two returns there do make sense. The first one is associated with the else branch. As the reverse indenting attempts to make clear :)
    • Wait a minute. Okay, I'm no C jockey, but doesn't this mean the final return statement could never be reached?
      if (SvPOK(sv)) {
        sbegin = SvPVX(sv);
        len = SvCUR(sv);
      }
      else if (SvPOKp(sv))
        sbegin = SvPV(sv, len);
      else
        return 1; /* Historic.  Wrong?  */

      return grok_number(sbegin, len, NULL);
      I've got my K&R right here, buddy! ;)
      --
      The great thing about multitasking is that several things can go wrong at once.
      • Re:Blocks in C (Score:4, Informative)

        by davorg (18) <dave@dave.org.uk> on 2004.02.02 9:02 (#27966) Homepage Journal
        No. The "return grok_number" still gets called if either SvPOK or SvPOKp return a true value.

        For example, if SvPOK returns true, then sbegin and len are set and the program execution moves to the first statement _after_ the if/else block, i.e. the "return grok_number".

        It's been a loong time since I wrote C, and my memory could be fading, but I'm pretty sure I'm right here.
        • Ah, duh. Got it. Just like what I'd want perl to do. Good thing I don't mess with C much.
          --
          The great thing about multitasking is that several things can go wrong at once.
  • tabstops (Score:3, Informative)

    by bart (450) <bart.lateur@pandora.be> on 2004.02.02 8:38 (#27964) Journal
    Did you happen to set your tabstops to 3 spaces?

    It looks to me like the source uses tab characters to indent code, and your editor shows it as 3 spaces instead of the traditional 8.