Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unwanted scalar references

8 views
Skip to first unread message

Ovid

unread,
Dec 17, 2006, 3:29:48 PM12/17/06
to perl6...@perl.org
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

--

Buy the book -- http://www.oreilly.com/catalog/perlhks/
Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/

0 new messages