#!./perl
BEGIN {
chdir 't' if -d 't';
}
use warnings;
use strict;
sub STORE { $_[0]->[$_[1]] = $_[2] }
sub FETCH { $_[0]->[$_[1]] }
sub STORESIZE { $#{$_[0]} = $_[1]+1 }
my $sch = {
'abc' => 1,
'def' => 2,
'jkl' => 3,
};
# basic normal array
$a = [];
$a->[0] = $sch;
$a->{'abc'} = 'ABC';
$a->{'def'} = 'DEF';
$a->{'jkl'} = 'JKL';
my $i = 0; # stop -w complaints
}
}
# quick check with tied array
$a = \@fake;
$a->[0] = $sch;
$a->{'abc'} = 'ABC';
# quick check with tied array
$a = \@fake;
$a->[0] = $sch;
$a->{'abc'} = 'ABC';
# quick check with tied array & tied hash
$a->[0] = \%fake;
$a->{'abc'} = 'ABC';
# hash slice
{
}
# evaluation in scalar context
my $avhv = [{}];
$avhv = [];
eval { $a = %$avhv };
$avhv = [{foo=>1, bar=>2}];
like (%$avhv, qr,^\d+/\d+,);
# check if defelem magic works
sub f {
is ($_[0], 'a');
$_[0] = 'b';
}
$a = [{key => 1}, 'a'];
f($a->{key});
is ($a->[1], 'b');
# check if exists() is behaving properly
$avhv = [{foo=>1,bar=>2,pants=>3}];
ok (!exists $avhv->{bar});
$avhv->{pants} = undef;
ok (exists $avhv->{pants});
ok (!exists $avhv->{bar});
$avhv->{bar} = 10;
ok (exists $avhv->{bar});
is ($avhv->{bar}, 10);
my $v = delete $avhv->{bar};
is ($v, 10);
ok (!exists $avhv->{bar});
is ("@x", "xxx zzz");
is ("$avhv->{bar}", "yyy");
# hash assignment
%$avhv = ();
my %hv = %$avhv;
ok (!grep defined, values %hv);
ok (!grep ref, keys %hv);
%$avhv = (foo => 29, pants => 2, bar => 0);
is ("@$avhv[1..3]", '29 0 2');
my $extra;
my @extra;
($extra, %$avhv) = ("moo", foo => 42, pants => 53, bar => "HIKE!");
%$avhv = ();
(%$avhv, $extra) = (foo => 42, pants => 53, bar => "HIKE!");
ok (!defined $extra);
@extra = qw(whatever and stuff);
%$avhv = ();
(%$avhv, @extra) = (foo => 42, pants => 53, bar => "HIKE!");
is (@extra, 0);
%$avhv = ();
(@extra, %$avhv) = (foo => 42, pants => 53, bar => "HIKE!");
is (@extra, 6);
# Check hash slices (BUG ID 20010423.002)
$avhv = [{foo=>1, bar=>2}];
@$avhv{"foo", "bar"} = (42, 53);
is ($avhv->{foo}, 42);
is ($avhv->{bar}, 53);