in reply to Scalar context of slice
Update: A slice in scalar context returns the last item in the slice, and that will be assigned to $broken_count. It's similar in effect to
my $foo = (1,2,3); # assigns 3 to $foo
map in scalar context returns what you're after: the length of the list. See map.
You may be more enlightened by the following small modification of your program:
my %bar = ( a => 'A', b => 'B', c => 'C', d => 'D', ); my $broken_count = @bar{'a', 'b'}; my $working_count = map {$_} @bar{'a', 'b'}; print "broken_count : $broken_count\n"; # B print "working_count: $working_count\n"; # 2
Update: Listy things in scalary context (there's no such thing as a "list in scalar context") are all special cased. You need to consult the relevant docs to see what will happen for each specific case.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Scalar context of slice (myth)
by tye (Sage) on Oct 03, 2008 at 21:06 UTC | |
by FunkyMonk (Bishop) on Oct 03, 2008 at 21:32 UTC | |
by tye (Sage) on Oct 03, 2008 at 22:38 UTC | |
by BrowserUk (Patriarch) on Oct 04, 2008 at 00:26 UTC | |
by tye (Sage) on Oct 04, 2008 at 06:12 UTC | |
| |
by jwkrahn (Abbot) on Oct 04, 2008 at 01:54 UTC | |
by JavaFan (Canon) on Oct 04, 2008 at 01:04 UTC | |
|