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

Dear Monks

Is there a way to pass all keys from 1 hash, as one string, to a subroutine in a one-liner ?
Here is the multi-line example
use warnings ; use strict ; my %h = ( 'a' => 1, 'b' => 1, 'c' => 1 ) ; my $str ; foreach ( keys %h ) { $str .= "$_ " } xyz( $str ) ; sub xyz { print shift ; }
So, I'm looking for something like
use warnings ; use strict ; my %h = ( 'a' => 1, 'b' => 1, 'c' => 1 ) ; xyz( "keys(%h)" ) ; sub xyz { print shift ; }
Doesn't work of course!

Any suggestions ?

Thnx
LuCa

UPDATE: thnx a lot!!

Replies are listed 'Best First'.
Re: need all keys from hash into one string (looking for 1-liner)
by derby (Abbot) on Jul 11, 2007 at 14:05 UTC

    my $str = join( ' ', keys %h );

    -derby
Re: need all keys from hash into one string (looking for 1-liner)
by xdg (Monsignor) on Jul 11, 2007 at 14:05 UTC
    xyz( join( " ", keys %h ) );

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: need all keys from hash into one string (looking for 1-liner)
by almut (Canon) on Jul 11, 2007 at 14:08 UTC

    Yet another way to do it

    my $str = "@{[keys %h]}";