in reply to Re: how to force scalar context (without scalar())?
in thread how to force scalar context (without scalar())?

I search for a way to list parameter to a function nicely.
function( aa => otherfunction(), bb => anotherone() );
but sometimes these functions return a list even if I'm only interested in the scalar value. so I write:
function( aa => otherfunction(), bb => scalar( anotherone() ) );
or
function( aa => otherfunction(), bb => anotherone() || '' );
but scalar() is a bit ugly and || something may change my return value. So I end up in using scalar or
my $another = anotherone(); <code> function( aa => otherfunction(), bb => $anotherone );
I just search for a nicer look for a scalar like function. Using a sub ss ($) { $_[0] } is not a real option for me. But perhaps something other can provide the same functionality.
Boris

Replies are listed 'Best First'.
Re^3: how to force scalar context (without scalar())?
by Aristotle (Chancellor) on Sep 19, 2004 at 15:13 UTC

    Ah, assignment… of course. You can inline it:

    function( aa => ( my $aa = otherfunction() ), bb => ( my $bb = anotherone() ), );

    That's all the options available.

    Makeshifts last the longest.

      That exactly answer my question. Thanks.
      Boris

        I really really wonder how you can think that

        func( aa => (my $aa = foo()), bb => (my $bb = bar()), );
        can be prettier than
        func( aa => scalar foo(), bb => scalar bar(), );
        One can argue code aesthetics all day, but your assignment can be a real pain in the long run and all it does is to fool the maintenance programmer into thinking that you especially want those values later. If you do this, although please don't, at least use a do block to handle the scoping issue (and make the maintenance programmer scratch his head a little less).
        func( aa => do { my $t = foo() }, bb => do { my $t = bar() }, );

        ihb

        Read argumentation in its context!