in reply to Apply function "keys" directly to function returning hash

Essentially you want to keep all of the even-numbered array elements, and discard all of the odd ones. Something like this will do that:
my $i = 1; print join(" ",grep { $i++ % 2 } l()),"\n";

Replies are listed 'Best First'.
Re: Re: Apply function "keys" directly to function returning hash
by wirrwarr (Monk) on Aug 26, 2003 at 10:35 UTC
    Hmm. Well, yes, this *does* get me the keys of the hash, but my intent was rather more general: I wanted to be able to call a perl internal function which takes a hash directly with a function call as a parameter, i.e. "somefunc func()".
    But thanks anyways!.

    daniel.
      It's not an internal function, but it does work exactly as you describe:
      #!/usr/bin/perl -sw use strict; sub somefunc(@) { my $i = 1; grep { $i++ % 2 } @_; } sub func { return ( 1 => "one", 2 => "two", 3 => "three", ); } print join(" ",somefunc func());