in reply to Anonymous scalar ref revisited

Your Solution 3 can be shorter:
f(\[]);
or even
f(\{});
Whether it is elegant is in the eye of the beholder. It surprised me that this worked, since the scalar is a reference to a reference, but it can be assigned to and modified, unlike f(\1) which gives a reference but is read-only (but does appear to return different addresses each time called).

Update: The following also appears to work in this case
f(\());
but this is an aberation of the subroutine call interface.
my $ref = \(); $$ref = 42;
Gives: Modification of a read-only value attempted

Replies are listed 'Best First'.
Re^2: Anonymous scalar ref revisited
by rovf (Priest) on Apr 06, 2010 at 11:36 UTC
    Your Solution 3 can be shorter:
    f(\[]);
    This is clever! I did not see first that this is really equivalent to my solution 3, but indeed it is. Plus, I find it simple and elegant. Well, a little bit obfuscating maybe, but meeting my requirements. Thanks a lot!

    -- 
    Ronald Fischer <ynnor@mm.st>