### Re: Getting keys of mapped hash?

```
On Tue, 2 Jan 2001, Peter Corlett wrote:

On Sat, Dec 30, 2000 at 06:35:18PM +, Tony Bowden wrote:
i.e. something akin to: my @sort = sort keys map { \$_ = 1 } @list;

I'm thinking that this might work:

my @sort=sort keys %{ +{ map { \$_ = undef } @list } };

Maybe I'm missing something here, but how is this different to

my @sort = sort @list;

?

S.

--
Shevek
I am the Borg.
?sub {\$s*{\$s-1}} :sub {1}; }; goto \$AUTOLOAD; } print {'4'};

```

### Re: Getting keys of mapped hash?

```
On Wed, 3 Jan 2001, Shevek wrote:
my @sort=sort keys %{ +{ map { \$_ = undef } @list } };
Maybe I'm missing something here, but how is this different to
my @sort = sort @list;

values in @sort are unique?

```

### Getting keys of mapped hash?

```

OK, my brain has fried.

How can I do this:

my @list = qw/foo bar foo baz/;
my %hash = map { \$_ = 1 } @men;
my @sort = sort keys %hash;
print "We have @sort\n"; # foo bar baz

without the %hash?

i.e. something akin to: my @sort = sort keys map { \$_ = 1 } @list;

I've tried so many variations that my brain is refusing to tell me the

Tony
--
-
Tony Bowden | Belfast, NI | [EMAIL PROTECTED] | www.tmtm.com | www.blackstar.co.uk
he knows the use of ashes, he worships God with ashes
-

```

### Re: Getting keys of mapped hash?

```
On Sat, Dec 30, 2000 at 06:35:18PM +, Tony Bowden wrote:
i.e. something akin to: my @sort = sort keys map { \$_ = 1 } @list;

I'm thinking that this might work:

my @sort=sort keys %{ +{ map { \$_ = undef } @list } };

```

### RE: Getting keys of mapped hash?

```

my @sort=sort keys %{ +{ map { \$_ = undef } @list } };
^^

??

What does +{} do???

```

### Re: Getting keys of mapped hash?

```
On Tue, Jan 02, 2001 at 03:21:15PM -, Jonathan Peterson wrote:

my @sort=sort keys %{ +{ map { \$_ = undef } @list } };
^^

??

What does +{} do???

It says 'Yes damnit, I want an anonymous hash here, not one of those pesky
block thingies'

--
Richard Clamp [EMAIL PROTECTED]

```

### RE: Getting keys of mapped hash?

```
What does +{} do???

It says 'Yes damnit, I want an anonymous hash here, not one
of those pesky
block thingies'

Ah. Not closely related to the concept of addition then. Couldn't they have
used !%{} or +%{} or something? Also, what _IS_ +{ in this case? It's not an
operator, so is +{ simply a modified kind of open bracket with special
meaning?

Is this explained in the latested Camel, because it doesn't show up in my
pocket refernce at all

```

### Re: Getting keys of mapped hash?

```
On Tue, Jan 02, 2001 at 03:36:17PM -, Jonathan Peterson wrote:
[ on +{ ... } ]
Is this explained in the latested Camel, because it doesn't show up in my
pocket refernce at all

It's almost a compile-time pragma, and I'm fairly sure it's in the camel.
Anyway, "perlop" has this to say:

Unary "+" has no effect whatsoever, even on strings.  It
is useful syntactically for separating a function name
from a parenthesized expression that would otherwise be
interpreted as the complete list of function arguments.
(See examples above under the section on Terms and List
Operators (Leftward).)

and in "perlref":

3.  A reference to an anonymous hash can be created using
curly brackets:

\$hashref = {
'Clyde' = 'Bonnie',
};

Anonymous hash and array composers like these can be
intermixed freely to produce as complicated a
structure as you want.  The multidimensional syntax
described below works for these too.  The values above
are literals, but variables and expressions would work
just as well, because assignment operators in Perl
(even within local() or my()) are executable
statements, not compile-time declarations.

Because curly brackets (braces) are used for several
other things including BLOCKs, you may occasionally
have to disambiguate braces at the beginning of a
statement by putting a + or a return in front so that
Perl realizes the opening brace isn't starting a
BLOCK.  The economy and mnemonic value of using
curlies is deemed worth this occasional extra hassle.

For example, if you wanted a function to make a new
hash and return a reference to it, you have these
options:

sub hashem {{ @_ } }   # silently wrong
sub hashem {   +{ @_ } }   # ok
sub hashem { return { @_ } }   # ok

On the other hand, if you want the other meaning, you
can do this:

sub showem {{ @_ } }   # ambiguous (currently ok, but may
change)
sub showem {   {; @_ } }   # ok
sub showem { { return @_ } }   # ok

Note how the leading +{ and {; always serve to
disambiguate the expression to mean either the HASH
reference, or the BLOCK.

```