Showing posts with label leaning. Show all posts
Showing posts with label leaning. Show all posts

Thursday, June 5, 2008

Leaning Toothpick Syndrome

One thing that's always bothered me about PHP is it's lack of a qq style operator. For example, in Perl, I could do something like this:

print qq/a $fun "string" with "double quotes"/;

In PHP it'd be something gross like:

print "a $fun \"string\" with \"double quotes\"";

Anyway, I found a nice solution that's been right under my nose all this time:

printf('a %s "string" with "double quotes"', $fun);

This is quite a bit cleaner for things like hyperlinks, so I thought I'd pass it along.

Ruby borrows quite a few ideas from Perl, and has a very nice %Q operator:

print %Q/a #{fun} "string" with "double quotes"/

going even further, you can use %r for regexp:

mystring =~ %r{/usr/src/linux} # no leaning toothpick required

or in Perl:

$mystring =~ m#/usr/src/linux#