FAQ
Hi all,

Thanks for the answers to my previous questions. I do appreciate it.

Today's stumper is this:

sub decode(*@list) returns Array {
gather {
for @list -> $elem {
take $elem.isa(Array) ?? $elem[1] xx $elem[0] !! $elem;
}
}
}
decode( [3, "a"], "b", [1, "c"] ).perl.say;

That prints:

("a", "a", "a", \"b", "c")

How do I dereference "b"? Heck, why is it a reference in the first
place?

Actually, I have found one way to dereference is, but it seems wrong
and buggy (using a prefix ++):

sub decode(*@list) returns Array {
gather {
for @list -> $elem {
take $elem.isa(Array) ?? $elem[1] xx $elem[0] !! ++$elem;
}
}
}
decode( [3, "a"], "b", [1, "c"] ).perl.say;

Oddly, using the postfix ++ gives me the error message I expect:

*** Can't modify constant item: VRef <Scalar::Const:0x32e37c8>
at 99.pugs line 215, column 18-69
99.pugs line 215, column 18-69

Cheers,
Ovid

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl6-users @
categoriesperl
postedDec 17, '06 at 8:29p
activeDec 17, '06 at 8:29p
posts1
users1
websiteperl6.org

1 user in discussion

Ovid: 1 post

People

Translate

site design / logo © 2021 Grokbase