Forcing an rvalue context on a scalar expression

Question

What is the simplest way to force an rvalue context on a scalar expression?

my @q;
foo($q[-1]);

This generates "Modification of non-creatable array value attempted, subscript -1" because it's trying to evaluate $q[-1] as an lvalue but I just wanted foo's $_[0]=undef.

I can easily, but not very elegantly, fix this by saying:

my $last_q = $q[-1];
foo($last_q);

Or even...

foo(my $last_q = $q[-1]);

Or, without a varaiable, but more perversely...

foo(&{sub { $q[-1] }});

Anyone got any less ugly solutions?

Brian's original post

Next