in reply to how to force scalar context (without scalar())?

scalar is the advertised way to do this and the only one that offers these exact semantics. (Even your prototyped function is simply exactly the same as scalar itself.) What do you have against it?

Makeshifts last the longest.

  • Comment on Re: how to force scalar context (without scalar())?

Replies are listed 'Best First'.
Re^2: how to force scalar context (without scalar())?
by borisz (Canon) on Sep 19, 2004 at 15:04 UTC
    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

      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