http://qs1969.pair.com?node_id=647786

tomazos has asked for the wisdom of the Perl Monks concerning the following question:

I want to take the literal source code of the parameter of a function call, and use it as a string at runtime. (...in a similiar fashion to the # operator in the context of a macro definition in the C/C++ preprocessor.)

sub literalize { ???? } sub assert($) { my ($condition) = @_; my $literal_condition_code = literalize(@_); if ($condition) { print "assertion failed: $literal_condition_code\n"; } } assert(42 == 24);

Output:

assertion failed: 42 == 24

The C/C++ code would be:

#define assert(condition) { if (!condition) { printf("assertion failed +: %s\n", #condition); } }

Anyone know how to do something like this in Perl?

Thanks,
Andrew.