Slash Boxes
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 ]

geoff (2013)

  reversethis-{gro ... om} {ta} {ffoeg}

see [] for personal information, links to presentations, GPG key, and so on.

Journal of geoff (2013)

Tuesday July 06, 2004
08:17 PM

perl is (now) more DWIMmy

[ #19720 ]
I just found out (via Stas) that more recent perl's have gotten a bit more DWIMmy.

a common mod_perl error used to look like this:

  $r->custom_response(SERVER_ERROR => 'yikes');

the (difficult to spot) problem is that => makes the SERVER_ERROR constant (500) into the string "SERVER_ERROR". so, you needed to use a comma instead, making the code look like this:

$r->custom_response(SERVER_ERROR, 'yikes');

well, with mod_perl 2.0 and perl-5.8.0 and later, you can use the => operator and still get your constant, so

$r->custom_response(Apache::SERVER_ERROR => 'yikes');

will now work in mod_perl 2.0-land. well, most of the time...

as it turns out, there is a caveat: the constant needs to be defined at least one level deep, meaning that if you imported the constants into your own namespace instead of the Apache:: namespace (as mod_perl 2.0 will let you) this

$r->custom_response(SERVER_ERROR => 'yikes');

still doesn't work. oh, well.

for those that don't give a hoot about mod_perl, (or are otherwise thus far confused), give this script a whirl with a few different perl versions:

package My;

use constant FOO => 0;  # My::FOO

package main;

use constant FOO => 1; # main::FOO

args(FOO => 'arrow');
args(FOO, 'comma');

args(main::FOO => 'arrow');
args(main::FOO, 'comma');

args(My::FOO => 'arrow');
args(My::FOO, 'comma');

sub args {
  print join ':', @_, "\n";

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Perl's constants are just a total pain. There are so many ways to accidentally break them: using them as a hash key, putting them in a quoted string, etc. It's just not worth it in my opinion. I just use regular old scalars, all caps.

    However, you can make the arrow operator stuff work by calling SERVER_ERROR as SERVER_ERROR().