NAME
Sub::Quotelike - Allow to define quotelike functions
SYNOPSIS
use Sub::Quotelike;
sub myq (') {
my $s = shift;
# Do something with $s...
return $s;
}
sub myqq (") {
my $s = shift;
# Do something with $s...
return $s;
}
print myq/abc def/;
print myqq{abc $def @ghi\n};
no Sub::Quotelike; # disallows quotelike functions
# in the remaining code
DESCRIPTION
This module allows to define quotelike functions, that mimic the syntax of the builtin operators q()
, qq()
, qw()
, etc.
To define a quotelike function that interpolates quoted text, use the new (")
prototype. For non-interpolating functions, use (')
. That's all.
To be polite with some indenters and syntax highlighters, the prototypes ('')
and ("")
are accepted as synonyms for (')
and ("")
.
BUGS
This module has bugs !!
It uses Filter::Simple internally. As I don't want to reimplement the perl tokenizer today, this means that it only performs some heuristic substitutions on the perl source code, to replace quotelike function calls by something more meaningful to plain perl 5.
Basically, if you have a quotelike function foo
, you'll be able to use without pain the variables $foo, @foo, and %foo, and to use &foo(...) if you want to bypass the quotelike syntax. 'foo' quoted by a fat comma (as in foo => 1
) and as a bare hash key ($hash{foo}
) also works. But you'll have problems if you write a literal word 'foo' in your code at other places (like in print "xxx foo yyy"
).
So my advice is to use meaningful names, unlikely to clash, for your quotelike functions : e.g. names that begin with 'q_' or 'qq_'.
AUTHOR
Copyright (c) 2001 Rafael Garcia-Suarez. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.