in reply to Is this a bug in splice?
Before your splice, I found only +, -, ARGV, INC and _ populated. After your splice you added $. The last array was, of course, empty. But the following code clearly populates it:for my $key (sort keys %main::) { next unless *{$main::{$key}}{ARRAY}; print "$key\n"; }
Edit: Simplified my code. I knew there was an easier way to write @{*main::{'$'}{ARRAY}}...#!/usr/bin/perl use strict; use warnings; my @list = map {[qw/foo bar blah baz/]} 1 .. 5; splice(@$, 0, 1, "hello", "world") for @list; print "@$\n";
Update: Upon thinking about it, this behaviour likely falls out of whatever logic makes $$ be recognized as a valid variable name. Because if you can name a variable $, then you should be able to put any sigil you want in front of that $. Or dereference it any way you want.
This is one of the astounding things about Perl. You start with a piece of behaviour and you say, "WTF?" Then you figure out what it did and you say, "Oh, here is what it did." Then you figure out why it did it and you go, "Oh, that is really quite reasonable for it to do." And suddenly it doesn't seem all that surprising.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is this a bug in splice?
by Limbic~Region (Chancellor) on Feb 20, 2008 at 03:22 UTC | |
by tilly (Archbishop) on Feb 20, 2008 at 03:27 UTC | |
by Limbic~Region (Chancellor) on Feb 20, 2008 at 03:35 UTC |