Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jdavidb (1361)

jdavidb
  (email not shown publicly)
http://voiceofjohn.blogspot.com/

J. David Blackstone has a Bachelor of Science in Computer Science and Engineering and nine years of experience at a wireless telecommunications company, where he learned Perl and never looked back. J. David has an advantage in that he works really hard, he has a passion for writing good software, and he knows many of the world's best Perl programmers.

Journal of jdavidb (1361)

Thursday August 19, 2010
04:55 PM

Cute caps

[ #40507 ]

I'm doing some quick code generation (the output is Java), and I found myself writing the below routine. I like it because of the names I picked for the variables. Not exactly self-documenting (although it is when you think about it), but this is throwaway. You can probably tell what the code is doing and why I named the variables as I did, and you might be entertained.

sub uc_prop
{
  my($prop) = @_;
  my $p = substr($prop, 0, 1);
  my $P = uc($p);
  my $rop = substr($prop, 1);
  return "$P$rop";
}

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.
    • No, I didn't. Thanks!
      --
      J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
  • LOL!

    And you were leaving comments on perl 5 and 6 replying to my criticisms of the language? Maybe its time to change your sig:

    "J. David works really hard reimplementing bult-in functions"

    Third-rate programmers, unite!

    • J. David writes a lot of one-off crap and wishes he wrote Perl full-time...

      My signature was a quote from someone here about me that was just so incredibly complimentary that I grabbed it and kept it. I suppose keeping it was a little pompous, but you know, it really built me up. And reminds me to try to be a good programmer even when circumstances aren't always conducive.

      To that end, even my one-off crap used strict and warnings, but I guess it still doesn't get me out of the guilt from reinventing a wh

      --
      J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
      • Hey, I think its a really nice quote; personally I wouldn't use it in my sig - maybe just quote it in my website or something, dunno. I would treasure it just like you did, though.

        ucfirst() has been around for ages, afaik. At least a decade, possibly much more.

        Why did you quit doing Perl full time? Was it a decision or did the market push you to it? Just curious. Do you actually want to go back to writing Perl full-time?

        I am currently doing Objective-C most of the time, and even though I miss some of

        • I changed jobs in 2007 in order to be able to move my family out close to my inlaws. In my previous job I was doing Perl with pressure to switch to Java. I traded that for doing Java after all, but closer to where I wanted to be, in a business environment that is somewhat saner.

          --
          J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
          • Similar to what I went through around 2005/2006. Except that what ended up deciding was how much more Java programmers were able to make, especially if they sported the magic "J2EE" incantations. Boy, was I wrong. When I first saw EJBs I knew it was time to get a new job.
  • sub uc_prop { # inefficient
      my $t = reverse shift;
      my $h = uc chop $t;
      return $h . reverse $t;
    }

    (Of course you can do the same thing more efficiently – and boringly:)

    sub uc_prop {
      my $t = shift;
      my $h = uc substr $t, 0, 1, '';
      return $h . $t;
    }

    (The following one might be more efficient. Or it may not be.)

    sub uc_prop {
      my $s = shift;
      my $h = uc substr $s, 0, 1, '';
      substr $s, 0, 0, $h;
      return $s;
    }

    (The first one is cool though.)