set. For example, you stick 10,000 things in a hash, but evaluating
%HASH in scalar context reveals C<"1/16">, which means only one out
of sixteen buckets has been touched, and presumably contains all
-10,000 of your items. This isn't supposed to happen.
+10,000 of your items. This isn't supposed to happen. If a tied hash
+is evaluated in scalar context, a fatal error will result, since this
+bucket usage information is currently not available for tied hashes.
You can preallocate space for a hash by assigning to the keys() function.
This rounds up the allocated buckets to the next power of two:
(F) The script you specified can't be opened for the indicated reason.
+=item Can't provide tied hash usage; use keys(%hash) to test if empty
+
+(F) When a hash is evaluated in scalar context, bucket usage is
+returned if the hash is populated, and false is returned if the hash
+is empty. Bucket usage is not currently available for tied hashes.
+To test if a hash is empty or populated, use keys(%hash) in scalar
+context instead.
+
=item Can't read CRTL environ
(S) A warning peculiar to VMS. Perl tried to read an element of %ENV
Tied filehandles are still incomplete. sysopen(), truncate(),
flock(), fcntl(), stat() and -X can't currently be trapped.
+The bucket usage information provided by C<scalar(%hash)> is not
+available. If C<%hash> is tied, this will currently result in a
+fatal error.
+
+Counting the number of entries in a hash via C<scalar(keys(%hash))> or
+C<scalar(values(%hash)>) is inefficient since it needs to iterate
+through all the entries with FIRSTKEY/NEXTKEY.
+
=head1 AUTHOR
Tom Christiansen
}
else if (gimme == G_SCALAR) {
SV* sv = sv_newmortal();
+ if (SvRMAGICAL(TARG) && mg_find(TARG, PERL_MAGIC_tied))
+ Perl_croak(aTHX_ "Can't provide tied hash usage; "
+ "use keys(%%hash) to test if empty");
if (HvFILL((HV*)TARG))
Perl_sv_setpvf(aTHX_ sv, "%ld/%ld",
(long)HvFILL((HV*)TARG), (long)HvMAX((HV*)TARG) + 1);
{
dSP; dTOPss;
HV *hv;
+ I32 gimme = GIMME_V;
if (SvROK(sv)) {
wasref:
RETURN;
}
else if (LVRET) {
- if (GIMME == G_SCALAR)
+ if (GIMME != G_SCALAR)
Perl_croak(aTHX_ "Can't return hash to lvalue scalar context");
SETs((SV*)hv);
RETURN;
skip('no caseless %ENV support') for 1..4;
}
+{
+ no warnings 'void';
+
# Make sure Errno hasn't been prematurely autoloaded
-ok !defined %Errno::;
+ ok !defined %Errno::;
# Test auto-loading of Errno when %! is used
-ok scalar eval q{
- my $errs = %!;
- defined %Errno::;
-}, $@;
+ ok scalar eval q{
+ %!;
+ defined %Errno::;
+ }, $@;
+}
# Make sure that Errno loading doesn't clobber $!