Recently in Code craft Category

Perlbuzz news roundup for 2010-03-09

| No Comments

These links are collected from the Perlbuzz Twitter feed. If you have suggestions for news bits, please mail me at andy@perlbuzz.com.

Help keep the world safe from SQL injection

| 3 Comments

A while back, I put up bobby-tables.com as a repository for showing people the right way to handle external data in their SQL calls. Whenever someone pops up on a mailing list or IRC and they're building SQL statements using external tainted data, you can just refer them to the site.

In the past few days, I've spiffed up the site (with design help from Jeana Clark) and added pages on Perl and PHP. I need more examples, though. It's 2010, and there's no reason anyone shouldn't know about parameterized SQL calls.

The site source is hosted on github, so if you have any contributions, please fork it and let me know about your applied changes, or you can email me directly.

Thanks!

P.S. In the next few days, I hope to fire up some redesign on perl101.org, too.

Perlbuzz news roundup for 2009-12-22

| No Comments

These links are collected from the Perlbuzz Twitter feed. If you have suggestions for news bits, please mail me at andy@perlbuzz.com.

Perlbuzz news roundup for 2009-12-08

| No Comments

These links are collected from the Perlbuzz Twitter feed. If you have suggestions for news bits, please mail me at andy@perlbuzz.com.

Perlbuzz news roundup for 2009-11-17

| 1 Comment

These links are collected from the Perlbuzz Twitter feed. If you have suggestions for news bits, please mail me at andy@perlbuzz.com.

  • Pod::Simple 3.09 hits the CPAN (justatheory.com)
  • Strawberry Perl and the nightmare of installing Padre (use.perl.org)
  • A busy month for masak in Perl 6 (use.perl.org)
  • A productive week in Rakudo-land (use.perl.org)
  • Perl one-liners explained part III: Calculations (catonmat.net)
  • Handy one-liner to lowercase all filenames in a directory: ls | perl -lne'$x=lc;print qq{mv $_ $x}' | sh -x
  • Use CPAN's toolchain to improve your code (use.perl.org)
  • Future Perl snuck up on me (headrattle.blogspot.com)
  • Find the stupid bug in my progress indicator: say "$n so far" if ( $n % 100000 )";
  • I maeked u a shell: lolshell, written in Perl 6 (theintersect.org)
  • The horrible bug your command line Perl program probably has (perlbuzz.com)
  • Frozen Perl 2010 looking for speakers (news.perlfoundation.org)
  • apache2rest is a new framework for REST APIs under mod_perl2 (code.google.com)
  • Putting MySQL on a ramdisk to speed up tests (use.perl.org)
  • Generating Feedburner graphs (catonmat.net)

The horrible bug your command line Perl program probably has

| 4 Comments

Most programmers know you have to check return values from system
functions. Unless you're just starting out as a programmer, you
know that this is bad:

open( my $fh, '<', 'something.txt' );
while ( my $line = <$fh> ) {
    # do something with the input
}

If that open fails the program continues on. The call to
readline will fail, return undef as if we're at
the end of the file, and the user will be none the wiser. If you
have use warnings on, you'll get a "readline() on closed
filehandle", but that's not much help when you should be dying.

Instead, you should be opening your file like this:

my $filename = 'something.txt';
open( my $fh, '<', $filename ) or die "Can't open $filename: $!";

This way, your user gets a useful error message if something goes
wrong, but more importantly, the program doesn't continue as if
nothing is wrong, potentially doing what it should not.

GetOptions needs checking, too

Unfortunately, I see programs where otherwise-sensible programmers
ignore the return code of GetOptions.

use Getopt::Long;
GetOptions(
    'n=i' => \my $count,
);
# Do something that uses $count
print "Processing complete!\n";

There are any number of ways the user can call this program incorrectly:

$ perl foo -n
Option n requires an argument
Processing complete!

$ perl foo -n=five
Value "five" invalid for option n (number expected)
Processing complete!

$ perl foo -m=12
Unknown option: m
Processing complete!

In all three of these cases, the user made a mistake, but the program
lets it slide without a mention. The user's going to be disappointed
with the results.

The solution is simple: Always check the results of GetOptions().
The easiest way is to task && exit(1) after the call:

use Getopt::Long;
GetOptions(
    'n=i' => \my $count,
) or exit(1);

It's simple, effective, and prevents unexpected sorrow.

What editor/IDE do you use for Perl development?

| No Comments

Gabor Szabo is running a survey about Perl development:

I have set up a simple five-second poll to find out what editor(s) or IDE(s) people use for Perl development. I'd appreciate very much if you clicked on the link and answered the question. You can mark up to 3 answers.

Please also forward this mail in the company you are working and to people in your previous company so we can get a large and diverse set of responses.

The poll will be closed within a week or after we reached 1000 voters. Whichever comes first.

Perlbuzz news roundup for 2009-10-21

| 1 Comment

These links are collected from the Perlbuzz Twitter feed. If you have suggestions for news bits, please mail me at andy@perlbuzz.com.

ack 1.90 released

| 3 Comments

I just released ack version 1.90 to CPAN. If you don't know about ack, it's a text searching tool for programmers aimed specifically at searching large trees of code. Find out more at betterthangrep.com.

Here's the changelog for this version:

1.90        Mon Sep  7 23:24:24 CDT 2009
[ENHANCEMENTS]
Added Ada support.  Thanks to Shaun Patterson.

Added -r, -R and --recurse options as in grep.  They have no
effect because directory recursion is on by default.  Also added
--no-recurse for orthoganality. Thanks to Mark Stosberg and
Ryan Niebur.

Version in --version is prettier.  Thanks, Ori Avtalion.

Added an updated ack.bash_completion.sh from Adam James.

[FIXES]
Expanded --files-without-match to --files-without-matches.

Removed all the hi-bit characters, so we don't have any encoding
problems.  It's all entities now.

Fixed capture-stderr to localize some globals that were obscuring
errors.  Thanks very much to Christopher Madsen.

Fixed uninitialized errors in tickets #138 and #159.

[DOCUMENTATION]
Fixed an incorrect command line in the docs for -f.

Added notes on --pager.  Thanks to Mike Morearty.

[BUILD]
Made the squash program more robust when handling POD.  Thanks
to Kent Fredric.


1.89_02     Wed May 13 16:20:21 CDT 2009
[DISTRIBUTION]
Updated Makefile.PL to use new ExtUtils::MakeMaker features.
Thanks, Schwern.

[FEATURES]
--version now shows the version of Perl that ack is running
under, and the full path to the Perl executable.

Added new switches --color-match and --color-filename, which
let you define ACK_COLOR_MATCH and ACK_COLOR_FILENAME from the
command line.

Added new switch --column to display the column of the first
hit on the row.  Thanks to Eric Van Dewoestine.

Added .ss to --scheme.

[FIXES]
No longer die if you have a .tar.gz file in your tree.

More tweaks to get the detection of input and output pipes
working.

Fixed an amazingly bad call to cmp_ok() in t/ack-passthru.t.

[DOCUMENTATION]
Started an ack FAQ.

Hide your unnecessary details from the user

| 1 Comment

Too often I see user-facing text that includes far more detail than is necessary. My current example is this web app where I can upload files for my expense reports. The help screen tells me:

You can attach the following types of files:
  • Portable Document Format (.pdf)
  • Joint Photographic Experts Group (.jpg or .jpeg)
  • Graphic Interchange Format (.gif)
  • Tagged Image Format (.tif)
  • Windows OS/2 Bitmap Graphics (.bmp)

Why why why do they bother giving those unnecessary explanations of what the file extensions mean? What they really mean is:

You can attach .pdf, .jpg or .jpeg, .gif, .tif and .bmp files.

Has anyone ever said "Hey, Bob, can you send me that Joint Photographic Experts Group file?" No? Then why do you think that people want to read it?

« Business | Main Index | Archives | Community »